Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel Chart Type vertical value

From a long time i am trying to generate graph like this enter image description here

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 which chart type i should use or i am making any mistake. A

After changing chart type, it works perfectly fine but its not working for last row text. As shown in image below. enter image description here

like image 592
Hot Cool Stud Avatar asked Jan 12 '15 14:01

Hot Cool Stud


2 Answers

Yes, you need to change the chart type.

using Excel = Microsoft.Office.Interop.Excel;

chartPage1.ChartType = Excel.XlChartType.xlBarClustered

You may have to adjust gridlines depending on how you want them to appear. I can provide more code for that if needed.

Edit - Also, don't forget to do

chartPage1.PlotBy = Excel.XlRowCol.xlColumns;
like image 154
ShipOfTheseus Avatar answered Sep 22 '22 02:09

ShipOfTheseus


I don't know how but the moment i commented chartPage1.SetSourceData(chartRange1, Type.Missing); in code it works fine, might be possible two data source are set one by commented line and one by series collection.

like image 33
Hot Cool Stud Avatar answered Sep 18 '22 02:09

Hot Cool Stud