MESCIUS SPREAD for Windows Forms 15.0J サンプルコード集
チャートを追加する(データソースの使用)

シリーズのデータソースにシートのセル範囲を設定することにより、チャートオブジェクトを配置させることができます。

【実行例】

チャート

 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.Chart.LineSeries series1 = new FarPoint.Win.Chart.LineSeries();
   series1.SeriesNameDataSource = new FarPoint.Win.Spread.Chart.SeriesDataField(fpSpread1, "Values", "Sheet1!$B$1:$B$1", FarPoint.Win.Spread.Chart.SegmentDataType.Text);
   series1.Values.DataSource = new FarPoint.Win.Spread.Chart.SeriesDataField(fpSpread1, "Values", "Sheet1!$B$2:$B$5");
   series1.CategoryNames.DataSource = new FarPoint.Win.Spread.Chart.SeriesDataField(fpSpread1, "Values", "Sheet1!$A$2:$A$5", FarPoint.Win.Spread.Chart.SegmentDataType.Text);

   FarPoint.Win.Chart.LineSeries series2 = new FarPoint.Win.Chart.LineSeries();
   series2.SeriesNameDataSource = new FarPoint.Win.Spread.Chart.SeriesDataField(fpSpread1, "Values", "Sheet1!$C$1:$C$1", FarPoint.Win.Spread.Chart.SegmentDataType.Text);
   series2.Values.DataSource = new FarPoint.Win.Spread.Chart.SeriesDataField(fpSpread1, "Values", "Sheet1!$C$2:$C$5");
   series2.CategoryNames.DataSource = new FarPoint.Win.Spread.Chart.SeriesDataField(fpSpread1, "Values", "Sheet1!$A$2:$A$5", FarPoint.Win.Spread.Chart.SegmentDataType.Text);

   FarPoint.Win.Chart.LineSeries series3 = new FarPoint.Win.Chart.LineSeries();
   series3.SeriesNameDataSource = new FarPoint.Win.Spread.Chart.SeriesDataField(fpSpread1, "Values", "Sheet1!$D$1:$D$1", FarPoint.Win.Spread.Chart.SegmentDataType.Text);
   series3.Values.DataSource = new FarPoint.Win.Spread.Chart.SeriesDataField(fpSpread1, "Values", "Sheet1!$D$2:$D$5");
   series3.CategoryNames.DataSource = new FarPoint.Win.Spread.Chart.SeriesDataField(fpSpread1, "Values", "Sheet1!$A$2:$A$5", FarPoint.Win.Spread.Chart.SegmentDataType.Text);

   // 折れ線グラフを設定します
   FarPoint.Win.Chart.YPlotArea plotArea = new FarPoint.Win.Chart.YPlotArea();
   plotArea.Location = new PointF(0.2f, 0.2f);
   plotArea.Size = new SizeF(0.55f, 0.6f);
   plotArea.Series.Add(series1);
   plotArea.Series.Add(series2);
   plotArea.Series.Add(series3);

   // ラベルを設定します
   FarPoint.Win.Chart.LabelArea label = new FarPoint.Win.Chart.LabelArea();
   label.Text = "四半期別";
   label.Location = new PointF(0.5f, 0.02f);
   label.AlignmentX = 0.5f;
   label.AlignmentY = 0f;

   // 凡例を設定します
   FarPoint.Win.Chart.LegendArea legend = new FarPoint.Win.Chart.LegendArea();
   legend.Location = new PointF(0.98f, 0.5f);
   legend.AlignmentX = 1f;
   legend.AlignmentY = 0.5f;

   // チャートモデルに各情報を追加します
   FarPoint.Win.Chart.ChartModel model = new FarPoint.Win.Chart.ChartModel();
   model.LabelAreas.Add(label);
   model.LegendAreas.Add(legend);
   model.PlotAreas.Add(plotArea);

   // SPREADチャートにチャートモデルを設定します
   FarPoint.Win.Spread.Chart.SpreadChart chart = new FarPoint.Win.Spread.Chart.SpreadChart();
   chart.Size = new Size(250, 200);
   chart.Location = new Point(250, 30);
   chart.Model = model;

   // シートにSPREADチャートを追加します
   fpSpread1.Sheets[0].Charts.Add(chart);

 }
 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 series1 As New FarPoint.Win.Chart.LineSeries()
   series1.SeriesNameDataSource = New FarPoint.Win.Spread.Chart.SeriesDataField(FpSpread1, "Values", "Sheet1!$B$1:$B$1", FarPoint.Win.Spread.Chart.SegmentDataType.Text)
   series1.Values.DataSource = New FarPoint.Win.Spread.Chart.SeriesDataField(FpSpread1, "Values", "Sheet1!$B$2:$B$5")
   series1.CategoryNames.DataSource = New FarPoint.Win.Spread.Chart.SeriesDataField(FpSpread1, "Values", "Sheet1!$A$2:$A$5", FarPoint.Win.Spread.Chart.SegmentDataType.Text)

   Dim series2 As New FarPoint.Win.Chart.LineSeries()
   series2.SeriesNameDataSource = New FarPoint.Win.Spread.Chart.SeriesDataField(FpSpread1, "Values", "Sheet1!$C$1:$C$1", FarPoint.Win.Spread.Chart.SegmentDataType.Text)
   series2.Values.DataSource = New FarPoint.Win.Spread.Chart.SeriesDataField(FpSpread1, "Values", "Sheet1!$C$2:$C$5")
   series2.CategoryNames.DataSource = New FarPoint.Win.Spread.Chart.SeriesDataField(FpSpread1, "Values", "Sheet1!$A$2:$A$5", FarPoint.Win.Spread.Chart.SegmentDataType.Text)

   Dim series3 As New FarPoint.Win.Chart.LineSeries()
   series3.SeriesNameDataSource = New FarPoint.Win.Spread.Chart.SeriesDataField(FpSpread1, "Values", "Sheet1!$D$1:$D$1", FarPoint.Win.Spread.Chart.SegmentDataType.Text)
   series3.Values.DataSource = New FarPoint.Win.Spread.Chart.SeriesDataField(FpSpread1, "Values", "Sheet1!$D$2:$D$5")
   series3.CategoryNames.DataSource = New FarPoint.Win.Spread.Chart.SeriesDataField(FpSpread1, "Values", "Sheet1!$A$2:$A$5", FarPoint.Win.Spread.Chart.SegmentDataType.Text)

   ' 折れ線グラフを設定します
   Dim plotArea As New FarPoint.Win.Chart.YPlotArea()
   plotArea.Location = New PointF(0.2F, 0.2F)
   plotArea.Size = New SizeF(0.55F, 0.6F)
   plotArea.Series.Add(series1)
   plotArea.Series.Add(series2)
   plotArea.Series.Add(series3)

   ' ラベルを設定します
   Dim label As New FarPoint.Win.Chart.LabelArea()
   label.Text = "四半期別"
   label.Location = New PointF(0.5F, 0.02F)
   label.AlignmentX = 0.5F
   label.AlignmentY = 0.0F

   ' 凡例を設定します
   Dim legend As New FarPoint.Win.Chart.LegendArea()
   legend.Location = New PointF(0.98F, 0.5F)
   legend.AlignmentX = 1.0F
   legend.AlignmentY = 0.5F

   ' チャートモデルに各情報を追加します
   Dim model As New FarPoint.Win.Chart.ChartModel()
   model.LabelAreas.Add(label)
   model.LegendAreas.Add(legend)
   model.PlotAreas.Add(plotArea)

   ' SPREADチャートにチャートモデルを設定します
   Dim chart As New FarPoint.Win.Spread.Chart.SpreadChart()
   chart.Size = New Size(250, 200)
   chart.Location = New Point(250, 30)
   chart.Model = model

   ' シートにSPREADチャートを追加します
   FpSpread1.Sheets(0).Charts.Add(chart)

 End Sub

 

 


© MESCIUS inc. All rights reserved.