C# show chart values on chart top

1.4k Views Asked by At

I have created the chart using C# interop. I want to show the exact values on tip of the bar chart. How can I do it? My code is here.

    Range chartRange;

    Object misValue = System.Reflection.Missing.Value;

    ChartObjects xlCharts = (ChartObjects)sheet0.ChartObjects(Type.Missing);

    ChartObject myChart = (ChartObject)xlCharts.Add(10, 70, 250, 250);

    Chart chartPage = myChart.Chart;

    chartRange = sheet0.get_Range("$G$2:$G$12,$AB$2:$AB$12,$AT$2:$AT$12", misValue);

    SeriesCollection scl = myChart.Chart.SeriesCollection();

    Series xlSeries = scl.NewSeries();

    chartPage.SetSourceData(chartRange, misValue);

    xlSeries.XValues = sheet0.get_Range("A3:A12");

    chartPage.ChartType = XlChartType.xlColumnClustered;

    chartPage.Location(XlChartLocation.xlLocationAsNewSheet, "Islamic Summary Chart");

Please help me get the values on tip of the chart.

Thank you.

1

There are 1 best solutions below

0
Mitja Bezenšek On

I don't think you can easily put them on the top on a clustered column chart.

DataLabels.Position 

property is the one to look at, but even the

XlDataLabelPosition.xlLabelPositionAbove;

won't work for your type of chart.

One solution for you is to add another series as a XY scatter chart type, hide the points and display the data labels on that series since you can display it above the points. The values can be exactly the same as you have them now.