Как добавить Excel линейную диаграмму с несколькими сериями, используя Excel-Interop VSTO - PullRequest
0 голосов
/ 20 июня 2019

Я хочу создать линейный график с несколькими рядами.Я написал следующий код.Хотя это не дает мне ожидаемый результат.


activeSheet.Shapes.AddChart2(332, XlChartType.xlLineMarkers).Select();
activeChart = workBooks.ActiveChart;
activeChart.ChartTitle.Text = UtilityLibrary.FirstCharToUpper(objTabulationList[n].WordSearch);
// X axis name
activeChart.Axes(XlAxisType.xlCategory, XlAxisGroup.xlPrimary).HasTitle = true;
activeChart.Axes(XlAxisType.xlCategory, XlAxisGroup.xlPrimary).AxisTitle.Characters.Text = UtilityLibrary.FirstCharToUpper(axisLabel1);
// y-axis name
activeChart.Axes(XlAxisType.xlValue, XlAxisGroup.xlPrimary).HasTitle = true;
activeChart.Axes(XlAxisType.xlValue, XlAxisGroup.xlPrimary).AxisTitle.Characters.Text = UtilityLibrary.FirstCharToUpper(activeSheet.Range[copyStart].Offset[0, 0].Value);
// Positioning the chart
chartposition = activeSheet.Range[txtAnalysisGraphicPlacement.Text].Offset[cellIndexToShift, 8 * n].Address;
activeChart.Parent.Top = activeSheet.Range[chartposition].Top;
activeChart.Parent.Left = activeSheet.Range[chartposition].Left;
SeriesCollection seriesCollection = (SeriesCollection)activeChart.SeriesCollection(Type.Missing);
Series series = seriesCollection.NewSeries();
series.Values = activeSheet.Range["E1:E10"].Value;
//series.XValues = activeSheet.UsedRange.Columns[activeSheet.Range[textBox1.Text].Column];
Series series2 = seriesCollection.NewSeries();
series2.Values = activeSheet.Range["F1:F10"].Value;
//series2.XValues = activeSheet.UsedRange.Columns[activeSheet.Range[textBox1.Text].Column];
//series2.AxisGroup = XlAxisGroup.xlSecondary;
//Series series3 = activeChart.SeriesCollection(1);
//series3.Values = activeSheet.UsedRange.Columns[activeSheet.Range[textBox3.Text].Column];
//series3.XValues = activeSheet.UsedRange.Columns[activeSheet.Range[textBox3.Text].Column];
//Series series4 = activeChart.SeriesCollection(1);
//series4.Values = activeSheet.UsedRange.Columns[activeSheet.Range[textBox4.Text].Column];
//series4.XValues = activeSheet.UsedRange.Columns[activeSheet.Range[textBox4.Text].Column];
//Series series5 = activeChart.SeriesCollection(1);
//series5.Values = activeSheet.UsedRange.Columns[activeSheet.Range[textBox5.Text].Column];
//series5.XValues = activeSheet.UsedRange.Columns[activeSheet.Range[textBox5.Text].Column];
//Series series6 = activeChart.SeriesCollection(1);
//series6.Values = activeSheet.UsedRange.Columns[activeSheet.Range[textBox6.Text].Column];
//series6.XValues = activeSheet.UsedRange.Columns[activeSheet.Range[textBox6.Text].Column];

...