Vertical Value Excel Chart Type

Since ancient times, I have been trying to create a graph like this enter image description here

The codes I tried.

Excel.Range chartRange1; Excel.ChartObjects xlCharts1 = (Excel.ChartObjects)worksheet.ChartObjects(Type.Missing); Excel.ChartObject myChart1 = (Excel.ChartObject)xlCharts1.Add(350, 500, 500, 350); Excel.Chart chartPage1 = myChart1.Chart; chartRange1 = worksheet.get_Range("A33", "b56"); chartPage1.SetSourceData(chartRange1, Type.Missing); chartPage1.ChartType = Excel.XlChartType.xlBarStacked; Excel.Range xValues = worksheet.Range["B33", "B56"]; Excel.Range values = worksheet.Range["a33", "a56"]; Excel.SeriesCollection seriesCollection = (Excel.SeriesCollection)chartPage1.SeriesCollection(); Excel.Series series1 = seriesCollection.NewSeries(); series1.XValues = xValues; series1.Values = values; 

Please help what type of chart should I use, or am I making any mistake. A

After changing the type of chart, it works fine, but does not work for the text of the last line. As shown in the picture below. enter image description here

+6
source share
2 answers

Yes, you need to change the type of chart.

 using Excel = Microsoft.Office.Interop.Excel; chartPage1.ChartType = Excel.XlChartType.xlBarClustered 

You may need to adjust the grid lines depending on how you want them to be displayed. I can provide more code for this if necessary.

Edit - Also remember to do

 chartPage1.PlotBy = Excel.XlRowCol.xlColumns; 
+8
source

I do not know how, but at that moment when I commented on chartPage1.SetSourceData(chartRange1, Type.Missing); in the code, it works fine, it is possible that two data sources are set by one scrolling line and one sequence.

+1
source

Source: https://habr.com/ru/post/980872/


All Articles