I'm having some problems trying to create a chart with two series on two Y axes. The first series should be a line series on the left axis and the second series should be a column series on the right axis.
I'm seeing two problems at this point:
1) As soon as I add the second (column) series to the chart, the first series turns into a column series too.
2) The SecondaryValueAxis is showing up on the left of the chart beside the PrimaryValueAxis. I would prefer it on the right side of the chart.
This is the code I'm using:
ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Create(5);
IWorksheet sheet = workbook.Worksheets[0];
// Inserting sample data for the chart.
sheet.Range["A1"].Text = "Date";
sheet.Range["B1"].Text = "LeftYAxis";
sheet.Range["C1"].Text = "RightYAxis";
// Months
sheet.Range["A2"].DateTime = new DateTime(2008, 12, 9);
sheet.Range["A3"].DateTime = new DateTime(2008, 12, 10);
sheet.Range["A4"].DateTime = new DateTime(2008, 12, 11);
sheet.Range["A5"].DateTime = new DateTime(2008, 12, 12);
sheet.Range["B2"].Number = 20.6;
sheet.Range["B3"].Number = 20.61;
sheet.Range["B4"].Number = 19.45;
sheet.Range["B5"].Number = 19.36;
sheet.Range["C2"].Number = 80.49959;
sheet.Range["C3"].Number = 61.5017;
sheet.Range["C4"].Number = 83.62421;
sheet.Range["C5"].Number = 78.1308;
// Embedded Chart
IChartShape chart = sheet.Charts.Add();
// Setting chart type.
chart.ChartType = ExcelChartType.Line;
//chart.PrimaryValueAxis.MajorGridLines.Border.LinePattern = ExcelChartLinePattern.Dot;
// LeftAxisSeries
IChartSerie leftAxisSeries = chart.Series.Add("LeftAxis", ExcelChartType.Line);
leftAxisSeries.Values = sheet.Range["B2:B5"];
// RightAxisSeries
IChartSerie rightAxisSeries = chart.Series.Add("RightAxis", ExcelChartType.Column_Clustered);
rightAxisSeries.Values = sheet.Range["C2:C5"];
rightAxisSeries.UsePrimaryAxis = false;
chart.PrimaryCategoryAxis.CategoryLabels = sheet.Range["A2:A5"];
chart.SecondaryCategoryAxis.CategoryLabels = sheet.Range["A2:A5"];
chart.SecondaryCategoryAxis.Visible = false;
//Export(workbook);
workbook.Close();
excelEngine.Dispose();
I'm attaching two example spreadsheets, Goal.xls shows about what I'm hoping to get, SF.xls shows what I'm getting.
Thanks,
Bill Massie
sf_7c70e207.zip