Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot 2 kinds of chart on the same chart use EPPlus

I want to draw 2 different type series (i.e. Column & Line) on one chart in EPPlus (a COM helping export Excel file). Anybody know how to do that. Thanks in advance.

like image 705
Han Avatar asked Nov 02 '12 05:11

Han


2 Answers

Finally, I've found my answer. Link ref: http://epplus.codeplex.com/wikipage?title=FAQ

How can I add a series with a different chart type to my chart?

Here's how you do...

ExcelChart chart = worksheet.Drawings.AddChart("chtLine", eChartType.LineMarkers);        
var serie1= chart.Series.Add(Worksheet.Cells["B1:B4"],Worksheet.Cells["A1:A4"]);
//Now for the second chart type we use the chart.PlotArea.ChartTypes collection...
var chartType2 = chart.PlotArea.ChartTypes.Add(eChartType.ColumnClustered);
var serie2 = chartType2.Series.Add(Worksheet.Cells["C1:C4"],Worksheet.Cells["A1:A4"]);
like image 72
Han Avatar answered Nov 07 '22 18:11

Han


You can do it like this...

var chartType2 = chart.PlotArea.ChartTypes.Add(eChartType.ColumnClustered)as ExcelBarChart;
(ExcelBarChartSerie) serie2 = (ExcelBarChartSerie) chartType2.Series.Add(Worksheet.Cells["C1:C4"],Worksheet.Cells["A1:A4"]);
serie2.DataLabel.ShowValue = true;
like image 38
Farooq Mushtaq Avatar answered Nov 07 '22 20:11

Farooq Mushtaq