チャートのグラフ作成時のデータ系列のオプションについて、
第2軸のデータ系列の作成方法を教えていただきたいです。
//単純に作成すると主軸で作成される認識
Chart.NSeries.Add(データ範囲指定, true);
Chart.NSeries[1].Type = Aspose.Cells.Charts.ChartType.Line;
image.png (14.2 KB)
チャートのグラフ作成時のデータ系列のオプションについて、
第2軸のデータ系列の作成方法を教えていただきたいです。
//単純に作成すると主軸で作成される認識
Chart.NSeries.Add(データ範囲指定, true);
Chart.NSeries[1].Type = Aspose.Cells.Charts.ChartType.Line;
image.png (14.2 KB)
@M.F,
2番目の軸のグラフタイプのデータ範囲を指定する方法については、次のサンプルコードを参照してください。
例えば
サンプルコード:
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Get the first worksheet in the workbook
Worksheet worksheet = workbook.Worksheets[0];
//Adding a sample value to "A1" cell
worksheet.Cells["A1"].PutValue(50);
//Adding a sample value to "A2" cell
worksheet.Cells["A2"].PutValue(100);
//Adding a sample value to "A3" cell
worksheet.Cells["A3"].PutValue(150);
//Adding a sample value to "A4" cell
worksheet.Cells["A4"].PutValue(200);
//Adding a sample value to "B1" cell
worksheet.Cells["B1"].PutValue(60);
//Adding a sample value to "B2" cell
worksheet.Cells["B2"].PutValue(32);
//Adding a sample value to "B3" cell
worksheet.Cells["B3"].PutValue(50);
//Adding a sample value to "B4" cell
worksheet.Cells["B4"].PutValue(40);
//Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(ChartType.Column, 5, 2, 21, 15);
//Accessing the instance of the newly added chart
Chart chart = worksheet.Charts[chartIndex];
//Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B4"
chart.NSeries.Add("A1:B4", true);
//Setting the chart type of 2nd SeriesCollection to display as line chart
chart.NSeries[1].Type = ChartType.Line;
chart.NSeries[1].PlotOnSecondAxis = true;
chart.SecondValueAxis.IsVisible = true;
chart.PlotArea.Area.ForegroundColor = Color.White;
workbook.Save("e:\\test2\\customcharts1.xlsx");
うまくいけば、これは少し役立つでしょう。
ご回答ありがとうございます。
検証しまして疑問解決できました。
(Chart.NSeries[<インデックス番号>].PlotOnSecondAxis = true;
Chart.SecondValueAxis.IsVisible = true; が足りてませんでした。)
そのため、このTOPICはクローズしていただいて問題ありません。
迅速にご回答いただき、ありがとうございました。