【问题标题】:How to hide zero values in a pie chart with the EPPLUS library如何使用 EPPLUS 库在饼图中隐藏零值
【发布时间】:2017-09-27 12:37:49
【问题描述】:

我正在使用 c# 开发并使用 EPPLUS 库来创建 excel 表,特别是 我创建了饼图,其中也显示了零值,但我想删除它们。我找不到任何解决方法。在我使用的代码下方:

<pre>    int chart_RegionHeaderRow = 1;
int chart_RegionHeaderColumn = 13;
firstRowCategory = 2;
lastRowCategory = 2;
firstColCategory = 3;
lastColCategory = firstColCategory + pDeployVersionSet.Length - 1;

int firstColValue = 3;
int lastColValue = firstColValue + pDeployVersionSet.Length - 1;
int firstRowSerie = 3;

int rowCR = chart_RegionHeaderRow;
int colCR = chart_RegionHeaderColumn;

int chart_RegionColStep = 6;
int chart_RegionRowStep = 16;

//Create the Region chart WW
var chartWW = (ExcelPieChart)worksheet.Drawings.AddChart("pieChartDeployWW", eChartType.Pie);
chartWW.SetSize(300, 300);
chartWW.SetPosition(rowCR, 0, colCR, 0);
chartWW.Title.Text = "WW";

chartWW.DataLabel.ShowValue = true;
chartWW.DataLabel.ShowPercent = true;
chartWW.DataLabel.ShowLeaderLines = true;
indexSerie = firstRowSerie;
chartWW.Series.Add(ExcelRange.GetAddress(indexSerie + _RegionsSet.Length, 
     firstColValue, 
     indexSerie + _RegionsSet.Length,
     lastColValue),
       ExcelRange.GetAddress(firstRowCategory, firstColCategory, lastRowCategory, lastColCategory <code>

还有生成的 excel 文件:

enter image description here

我希望有人能给我指路。 谢谢

【问题讨论】:

标签: c# pie-chart epplus


【解决方案1】:

我的图表数据是从 .csv 文件中导入的,该文件将空白作为文本导入。 这帮助我摆脱了图表上的零值。

sheet.Cells["B33"].Clear();

我的图表是折线图,但它也可能对您有用。

【讨论】:

  • 它不起作用,请尝试检查代码和我发布的结果。谢谢
【解决方案2】:

只需将大小设为 0。 不是很优雅,但它有效。

var deletePieChart = ws.Drawings["Chart 6"] as ExcelPieChart;
deletePieChart.SetSize(0, 0);

【讨论】:

    猜你喜欢
    • 2016-01-01
    • 2012-06-05
    • 2011-01-04
    • 2013-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多