如何将值(不只是百分比)添加到Excel饼图?

我有这个代码:

private void WriteChartSheet() { _xlSheetChart = (Worksheet)_xlSheets.Item[2]; if (_xlSheetChart != null) { _xlSheetChart.Name = ProduceUsageChartSheetName; // Contract vs. non-Contract pie chart _xlSheetChart.Cells[1, 1] = "Contracted Items"; _xlSheetChart.Cells[1, 2] = "Non-Contracted Items"; _xlSheetChart.Cells[2, 1] = GetContractedItemsTotal(); _xlSheetChart.Cells[2, 2] = GetNonContractedItemsTotal(); ChartObjects xlCharts = (ChartObjects)_xlSheetChart.ChartObjects(Type.Missing); ChartObject contractChartObject = xlCharts.Add(0, 0, 300, 250); // left, top, width, height Chart contractChart = contractChartObject.Chart; Range chartRange = _xlSheetChart.get_Range("A1", "B2"); contractChart.SetSourceData(chartRange, Missing.Value); contractChart.ChartType = XlChartType.xlPie; //xl3DPie; contractChart.ApplyDataLabels(XlDataLabelsType.xlDataLabelsShowValue, XlDataLabelsType.xlDataLabelsShowLabel, true, false, false, true, false, true); . . . 

…产生这个饼图:

在这里输入图像说明

我非常喜欢,但是我也需要在馅饼中印上价值(例如,“Contracted Items”部分为“$ 361,779”,另一个为适当的值)。 我怎样才能做到这一点?

在C#中,“真/假”是什么决定什么价值显示:

从这里 :

 void ApplyDataLabels( XlDataLabelsType Type = XlDataLabelsType.xlDataLabelsShowValue, object LegendKey, object AutoText, object HasLeaderLines, object ShowSeriesName, object ShowCategoryName, object ShowValue, object ShowPercentage, object ShowBubbleSize, object Separator ) 

所以,根据情况调整TrueFalse

试验蝙蝠侠的信息,我想出了这个:

 contractChart.ApplyDataLabels(XlDataLabelsType.xlDataLabelsShowValue, false, true, false, false, false, true, true, false, false); 

这产生了这个:

在这里输入图像说明

我宁愿没有百分比中的领先“0”(显示“045”和“055”而不是显而易见和经济的“45”和“55”),但我可以和他们一起生活。