MESCIUS SPREAD for Windows Forms 17.0J サンプルコード集
チャートにシェイプを埋め込む

IChartObjectsインターフェースのオブジェクトに対してAddShapeメソッドを呼び出すことでチャートにシェイプを埋め込むことが可能です。チャート内のシェイプは通常のシェイプと同様に操作できますがシェイプをチャートの外に移動させることはできません。

  • 新しいスタイルシステム(LegacyBehaviorsプロパティがStyleを含まない場合)で有効です。
  • 拡張シェイプエンジン(EnhancedShapeEngineプロパティ)を有効にする必要があります。

【実行例】

private void Form1_Load(object sender, EventArgs e)
 {
  // 拡張シェイプエンジンを有効にします
  fpSpread1.Features.EnhancedShapeEngine = true;

  // データを設定します
  fpSpread1.AsWorkbook().ActiveSheet.Cells[0, 1].Value = "S1";
  fpSpread1.AsWorkbook().ActiveSheet.Cells[0, 2].Value = "S2";
  fpSpread1.AsWorkbook().ActiveSheet.Cells[0, 3].Value = "S3";

  fpSpread1.AsWorkbook().ActiveSheet.Cells[1, 0].Value = "1Q";
  fpSpread1.AsWorkbook().ActiveSheet.Cells[2, 0].Value = "2Q";
  fpSpread1.AsWorkbook().ActiveSheet.Cells[3, 0].Value = "3Q";
  fpSpread1.AsWorkbook().ActiveSheet.Cells[4, 0].Value = "4Q";

  fpSpread1.AsWorkbook().ActiveSheet.Cells[1, 1].Value = 50;
  fpSpread1.AsWorkbook().ActiveSheet.Cells[2, 1].Value = 30;
  fpSpread1.AsWorkbook().ActiveSheet.Cells[3, 1].Value = 20;
  fpSpread1.AsWorkbook().ActiveSheet.Cells[4, 1].Value = 40;

  fpSpread1.AsWorkbook().ActiveSheet.Cells[1, 2].Value = 30;
  fpSpread1.AsWorkbook().ActiveSheet.Cells[2, 2].Value = 15;
  fpSpread1.AsWorkbook().ActiveSheet.Cells[3, 2].Value = 50;
  fpSpread1.AsWorkbook().ActiveSheet.Cells[4, 2].Value = 20;

  fpSpread1.AsWorkbook().ActiveSheet.Cells[1, 3].Value = 10;
  fpSpread1.AsWorkbook().ActiveSheet.Cells[2, 3].Value = 40;
  fpSpread1.AsWorkbook().ActiveSheet.Cells[3, 3].Value = 25;
  fpSpread1.AsWorkbook().ActiveSheet.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);

  // チャートにシェイプを追加します
  fpSpread1.AsWorkbook().ActiveSheet.ChartObjects[0].Chart.Shapes.AddShape(GrapeCity.Spreadsheet.Drawing.AutoShapeType.LeftArrow, 180, 20, 50, 50);
}
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  ' 拡張シェイプエンジンを有効にします
  FpSpread1.Features.EnhancedShapeEngine = True

  ' データを設定します
  FpSpread1.AsWorkbook().ActiveSheet.Cells(0, 1).Value = "S1"
  FpSpread1.AsWorkbook().ActiveSheet.Cells(0, 2).Value = "S2"
  FpSpread1.AsWorkbook().ActiveSheet.Cells(0, 3).Value = "S3"

  FpSpread1.AsWorkbook().ActiveSheet.Cells(1, 0).Value = "1Q"
  FpSpread1.AsWorkbook().ActiveSheet.Cells(2, 0).Value = "2Q"
  FpSpread1.AsWorkbook().ActiveSheet.Cells(3, 0).Value = "3Q"
  FpSpread1.AsWorkbook().ActiveSheet.Cells(4, 0).Value = "4Q"

  FpSpread1.AsWorkbook().ActiveSheet.Cells(1, 1).Value = 50
  FpSpread1.AsWorkbook().ActiveSheet.Cells(2, 1).Value = 30
  FpSpread1.AsWorkbook().ActiveSheet.Cells(3, 1).Value = 20
  FpSpread1.AsWorkbook().ActiveSheet.Cells(4, 1).Value = 40

  FpSpread1.AsWorkbook().ActiveSheet.Cells(1, 2).Value = 30
  FpSpread1.AsWorkbook().ActiveSheet.Cells(2, 2).Value = 15
  FpSpread1.AsWorkbook().ActiveSheet.Cells(3, 2).Value = 50
  FpSpread1.AsWorkbook().ActiveSheet.Cells(4, 2).Value = 20

  FpSpread1.AsWorkbook().ActiveSheet.Cells(1, 3).Value = 10
  FpSpread1.AsWorkbook().ActiveSheet.Cells(2, 3).Value = 40
  FpSpread1.AsWorkbook().ActiveSheet.Cells(3, 3).Value = 25
  FpSpread1.AsWorkbook().ActiveSheet.Cells(4, 3).Value = 25

  ' データ領域およびスタイルを指定してチャートを設定します
  Dim range As FarPoint.Win.Spread.Model.CellRange = 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)

  ' チャートにシェイプを追加します
  FpSpread1.AsWorkbook().ActiveSheet.ChartObjects(0).Chart.Shapes.AddShape(GrapeCity.Spreadsheet.Drawing.AutoShapeType.LeftArrow, 180, 20, 50, 50)
 End Sub

 

 


© MESCIUS inc. All rights reserved.