Я пытаюсь нарисовать комбинированный график, как показано выше в Excel, используя C #.
Я могу нарисовать один график серии с кодом, приведенным ниже. Но у меня проблема с добавлением еще одной серии. Как я могу добавить дополнительную серию?
Ниже мой код:
Microsoft.Office.Interop.Excel.Application xlApp;
Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
Microsoft.Office.Interop.Excel.Worksheet xlWorksheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Microsoft.Office.Interop.Excel.Application();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
//add data
xlWorksheet.Cells[1, 1] = "Label";
xlWorksheet.Cells[1, 2] = "Date Time";
xlWorksheet.Cells[1, 3] = "Alarm Broadcaster";
xlWorksheet.Cells[1, 4] = "Alarm ID";
xlWorksheet.Cells[1, 5] = "Alarm Discription";
xlWorksheet.Cells[1, 6] = "Occurence";
xlWorksheet.Cells[1, 7] = "Cumuative Frequency";
for (int i = 0; i < list_alarmObj.Count; i++)
{
xlWorksheet.Cells[i + 2, 1] = list_alarmObj[i].discription;
xlWorksheet.Cells[i + 2, 2] = list_alarmObj[i].date;
xlWorksheet.Cells[i + 2, 3] = list_alarmObj[i].broadcaster;
xlWorksheet.Cells[i + 2, 4] = list_alarmObj[i].alarmid;
xlWorksheet.Cells[i + 2, 5] = list_alarmObj[i].discription;
xlWorksheet.Cells[i + 2, 6] = list_alarmObj[i].occurrence;
xlWorksheet.Cells[i + 2, 7] = cumulativeFreq[i];
}
Range chartRange;
ChartObjects xlCharts = (ChartObjects)xlWorksheet.ChartObjects(Type.Missing);
ChartObject myChart = (ChartObject)xlCharts.Add(10, 80, 300, 250);
Microsoft.Office.Interop.Excel.Chart chartPage = myChart.Chart;
string endrange = "f" + (list_alarmObj.Count + 1);
chartRange = xlWorksheet.get_Range("f1", endrange);
chartPage.SetSourceData(chartRange, misValue);
chartPage.ChartType = XlChartType.xlColumnClustered;
xlWorkBook.SaveAs("histogram-informations.xls", XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();