我有以下代码使用Epplus officeopenxml创建饼图。如果提供的值为0,我想隐藏数据标签,百分比和引导线。所有数据都填充在sheet1中,另一个数据表包含图表。
请帮帮我。
Dim unCommittedChart As OfficeOpenXml.Drawing.Chart.ExcelPieChart = worksheet4.Drawings.AddChart("UncommittedChart", OfficeOpenXml.Drawing.Chart.eChartType.Pie)
Dim r5, r6 As ExcelRange
Dim startColumnUncommitted As String = "A"
Dim endColumnUncommitted As String = "G"
Dim startIndexUncommitted As Integer = 9
Dim endIndexUncommitted As Integer = totalRow - 1 'this is determined based on the TOTAL Line from above code
r5 = worksheet.Cells(String.Concat(startColumnUncommitted, startIndexUncommitted.ToString(), ":", startColumnUncommitted, endIndexUncommitted))
r6 = worksheet.Cells(String.Concat(endColumnUncommitted, startIndexUncommitted.ToString(), ":", endColumnUncommitted, endIndexUncommitted))
unCommittedChart.Series.Add(r6, r5)
unCommittedChart.Style = OfficeOpenXml.Drawing.Chart.eChartStyle.Style2
unCommittedChart.Title.Text = "FY 2018 Uncommitted by Regional & Central Oversight Programs"
unCommittedChart.Legend.Remove()
unCommittedChart.SetPosition(5, 5, 5, 5)
unCommittedChart.SetSize(1040, 880)
Dim i As Integer = p + 1
For Each r As DataRow In ds.Tables(0).Rows
Dim k As Integer = 0
For j As Integer = 0 To ds.Tables(0).Columns.Count - 1
If Not skip.Contains(j) Then
If r.Item(j) Is DBNull.Value Then
worksheet.Cells(i, k + 1).Value = ""
Else
If k = 0 Then
worksheet.Cells(i, k + 1).Value = r.Item(j).ToString()
Else
worksheet.Cells(i, k + 1).Value = r.Item(j)
End If
End If
If r.Item(j) = "0" Then
unCommittedChart.DataLabel.ShowCategory = False
unCommittedChart.DataLabel.ShowPercent = False
unCommittedChart.DataLabel.ShowLeaderLines = False
Else
unCommittedChart.DataLabel.ShowCategory = True
unCommittedChart.DataLabel.ShowPercent = True
unCommittedChart.DataLabel.ShowLeaderLines = True
End If
k = k + 1
End If
Next
i = i + 1
Next
提前致谢。