MESCIUS SPREAD for Windows Forms 17.0J サンプルコード集 > チャート > チャートを追加する(データ領域を指定) |
SheetViewクラスのAddChartメソッド呼び出しにより、シート上には様々なチャートオブジェクトを配置させることができます。
引数にCellRangeクラスを設定することにより、シート上のデータによって、チャートを作成することができます。
private void Form1_Load(object sender, System.EventArgs e) { // データを設定します fpSpread1.Sheets[0].Cells[0, 1].Value = "S1"; fpSpread1.Sheets[0].Cells[0, 2].Value = "S2"; fpSpread1.Sheets[0].Cells[0, 3].Value = "S3"; fpSpread1.Sheets[0].Cells[1, 0].Value = "1Q"; fpSpread1.Sheets[0].Cells[2, 0].Value = "2Q"; fpSpread1.Sheets[0].Cells[3, 0].Value = "3Q"; fpSpread1.Sheets[0].Cells[4, 0].Value = "4Q"; fpSpread1.Sheets[0].Cells[1, 1].Value = 50; fpSpread1.Sheets[0].Cells[2, 1].Value = 30; fpSpread1.Sheets[0].Cells[3, 1].Value = 20; fpSpread1.Sheets[0].Cells[4, 1].Value = 40; fpSpread1.Sheets[0].Cells[1, 2].Value = 30; fpSpread1.Sheets[0].Cells[2, 2].Value = 15; fpSpread1.Sheets[0].Cells[3, 2].Value = 50; fpSpread1.Sheets[0].Cells[4, 2].Value = 20; fpSpread1.Sheets[0].Cells[1, 3].Value = 10; fpSpread1.Sheets[0].Cells[2, 3].Value = 40; fpSpread1.Sheets[0].Cells[3, 3].Value = 25; fpSpread1.Sheets[0].Cells[4, 3].Value = 25; // データ領域およスタイルを指定してチャートを設定します FarPoint.Win.Spread.Model.CellRange range = new FarPoint.Win.Spread.Model.CellRange(0, 0, 5, 4); fpSpread1.Sheets[0].AddChart(range, typeof(FarPoint.Win.Chart.LineSeries), 250, 200, 250, 30, FarPoint.Win.Chart.ChartViewType.View2D, true); }
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load ' データを設定します FpSpread1.Sheets(0).Cells(0, 1).Value = "S1" FpSpread1.Sheets(0).Cells(0, 2).Value = "S2" FpSpread1.Sheets(0).Cells(0, 3).Value = "S3" FpSpread1.Sheets(0).Cells(1, 0).Value = "1Q" FpSpread1.Sheets(0).Cells(2, 0).Value = "2Q" FpSpread1.Sheets(0).Cells(3, 0).Value = "3Q" FpSpread1.Sheets(0).Cells(4, 0).Value = "4Q" FpSpread1.Sheets(0).Cells(1, 1).Value = 50 FpSpread1.Sheets(0).Cells(2, 1).Value = 30 FpSpread1.Sheets(0).Cells(3, 1).Value = 20 FpSpread1.Sheets(0).Cells(4, 1).Value = 40 FpSpread1.Sheets(0).Cells(1, 2).Value = 30 FpSpread1.Sheets(0).Cells(2, 2).Value = 15 FpSpread1.Sheets(0).Cells(3, 2).Value = 50 FpSpread1.Sheets(0).Cells(4, 2).Value = 20 FpSpread1.Sheets(0).Cells(1, 3).Value = 10 FpSpread1.Sheets(0).Cells(2, 3).Value = 40 FpSpread1.Sheets(0).Cells(3, 3).Value = 25 FpSpread1.Sheets(0).Cells(4, 3).Value = 25 ' データ領域およスタイルを指定してチャートを設定します Dim range As New FarPoint.Win.Spread.Model.CellRange(0, 0, 5, 4) FpSpread1.Sheets(0).AddChart(range, GetType(FarPoint.Win.Chart.LineSeries), 250, 200, 250, 30, FarPoint.Win.Chart.ChartViewType.View2D, True) End Sub