在c#中的打开xml图表上显示数据标签

时间:2014-09-19 06:17:56

标签: c# xml asp.net-mvc model-view-controller

我们使用open xml在exl导出中显示条形图,但它没有在数据上显示标签,例如每个条形图上方的值。 这是我正在使用的代码

BarChart barChart = plotArea.AppendChild<BarChart>(new BarChart(new BarDirection() { Val = new         EnumValue<BarDirectionValues>(BarDirectionValues.Column) },
                new BarGrouping() { Val = new EnumValue<BarGroupingValues>(BarGroupingValues.Clustered) }));
BarChartSeries barChartSeries = barChart.AppendChild<BarChartSeries>(new BarChartSeries(new Index()
                {
                    Val =
                        new UInt32Value(i)
                },
                    new Order() { Val = new UInt32Value(i) },
                    new SeriesText(new NumericValue() { Text = key })));

其中key是bar的数据值。但它仍然没有显示。任何人都可以告诉确切地放置数据标签的位置,以便在条形图中的每个条形图顶部可以看到值标签

1 个答案:

答案 0 :(得分:0)

您只需要创建一个DataLabels类,修改它们的外观并将其附加到系列中。希望这有帮助

        C.DataLabels dataLabels2 = new C.DataLabels();

        C.TextProperties textProperties2 = new C.TextProperties();
        A.BodyProperties bodyProperties2 = new A.BodyProperties();
        A.ListStyle listStyle2 = new A.ListStyle();

        A.Paragraph paragraph2 = new A.Paragraph();

        A.ParagraphProperties paragraphProperties2 = new A.ParagraphProperties();

        A.DefaultRunProperties defaultRunProperties2 = new A.DefaultRunProperties() { FontSize = 700 };

        A.SolidFill solidFill2 = new A.SolidFill();
        A.SchemeColor schemeColor2 = new A.SchemeColor() { Val = A.SchemeColorValues.Background1 };

        solidFill2.Append(schemeColor2);

        defaultRunProperties2.Append(solidFill2);

        paragraphProperties2.Append(defaultRunProperties2);
        A.EndParagraphRunProperties endParagraphRunProperties2 = new A.EndParagraphRunProperties() { Language = "en-US" };

        paragraph2.Append(paragraphProperties2);
        paragraph2.Append(endParagraphRunProperties2);

        textProperties2.Append(bodyProperties2);
        textProperties2.Append(listStyle2);
        textProperties2.Append(paragraph2);
        C.ShowLegendKey showLegendKey2 = new C.ShowLegendKey() { Val = false };
        C.ShowValue showValue2 = new C.ShowValue() { Val = true };
        C.ShowCategoryName showCategoryName2 = new C.ShowCategoryName() { Val = false };
        C.ShowSeriesName showSeriesName2 = new C.ShowSeriesName() { Val = false };
        C.ShowPercent showPercent2 = new C.ShowPercent() { Val = false };
        C.ShowBubbleSize showBubbleSize2 = new C.ShowBubbleSize() { Val = false };
        C.ShowLeaderLines showLeaderLines2 = new C.ShowLeaderLines() { Val = false };

        dataLabels2.Append(textProperties2);
        dataLabels2.Append(showLegendKey2);
        dataLabels2.Append(showValue2);
        dataLabels2.Append(showCategoryName2);
        dataLabels2.Append(showSeriesName2);
        dataLabels2.Append(showPercent2);
        dataLabels2.Append(showBubbleSize2);
        dataLabels2.Append(showLeaderLines2);


        barChartSeries2.Append(dataLabels2);