如何使用EPPLUS库隐藏饼图中的零值

时间:2017-09-27 12:37:50

标签: c# pie-chart epplus

我正在使用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

我希望有人可以给我指示。 谢谢

2 个答案:

答案 0 :(得分:0)

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

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

我的图表是折线图,但它也适用于你。

答案 1 :(得分:0)

只需将大小设为0。 不是很优雅,但可以。

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