MESCIUS SPREAD for Windows Forms 15.0J サンプルコード集
スパークラインを追加する

スパークラインを追加するには、SheetCellRangeクラスでデータ領域のセル範囲を作成しAddSparklineメソッドでシート上に追加します。

【実行例】

スパークライン

private void Form1_Load(object sender, EventArgs e)
{
  // シートに値を設定
  fpSpread1.ActiveSheet.Cells[0, 0].Value = 1;
  fpSpread1.ActiveSheet.Cells[0, 1].Value = 2;
  fpSpread1.ActiveSheet.Cells[0, 2].Value = -1;
  fpSpread1.ActiveSheet.Cells[0, 3].Value = 3;

  fpSpread1.ActiveSheet.Cells[1, 0].Value = 2;
  fpSpread1.ActiveSheet.Cells[1, 1].Value = -1;
  fpSpread1.ActiveSheet.Cells[1, 2].Value = 5;
  fpSpread1.ActiveSheet.Cells[1, 3].Value = 4;

  fpSpread1.ActiveSheet.Cells[2, 0].Value = -1;
  fpSpread1.ActiveSheet.Cells[2, 1].Value = 3;
  fpSpread1.ActiveSheet.Cells[2, 2].Value = 2;
  fpSpread1.ActiveSheet.Cells[2, 3].Value = 1;

  // セル範囲の定義
  FarPoint.Win.Spread.Chart.SheetCellRange data1 = new FarPoint.Win.Spread.Chart.SheetCellRange(fpSpread1.ActiveSheet, 0, 0, 1, 5);
  FarPoint.Win.Spread.Chart.SheetCellRange data2 = new FarPoint.Win.Spread.Chart.SheetCellRange(fpSpread1.ActiveSheet, 1, 0, 1, 5);
  FarPoint.Win.Spread.Chart.SheetCellRange data3 = new FarPoint.Win.Spread.Chart.SheetCellRange(fpSpread1.ActiveSheet, 2, 0, 1, 5);

  // スタイルを設定
  FarPoint.Win.Spread.ExcelSparklineSetting setting = new FarPoint.Win.Spread.ExcelSparklineSetting();
  setting.ShowMarkers = true;
  setting.ShowNegative = true;
  setting.NegativeColor = Color.Red;
  setting.SeriesColor = Color.Olive;

  fpSpread1.ActiveSheet.AddSparkline(data1, new FarPoint.Win.Spread.Model.CellRange(0, 4, 1, 1), FarPoint.Win.Spread.SparklineType.Column, setting);
  fpSpread1.ActiveSheet.AddSparkline(data2, new FarPoint.Win.Spread.Model.CellRange(1, 4, 1, 1), FarPoint.Win.Spread.SparklineType.Line, setting);
  fpSpread1.ActiveSheet.AddSparkline(data3, new FarPoint.Win.Spread.Model.CellRange(2, 4, 1, 1), FarPoint.Win.Spread.SparklineType.Winloss, setting);
}
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  ' シートに値を設定
  FpSpread1.ActiveSheet.Cells(0, 0).Value = 1
  FpSpread1.ActiveSheet.Cells(0, 1).Value = 2
  FpSpread1.ActiveSheet.Cells(0, 2).Value = -1
  FpSpread1.ActiveSheet.Cells(0, 3).Value = 3

  FpSpread1.ActiveSheet.Cells(1, 0).Value = 2
  FpSpread1.ActiveSheet.Cells(1, 1).Value = -1
  FpSpread1.ActiveSheet.Cells(1, 2).Value = 5
  FpSpread1.ActiveSheet.Cells(1, 3).Value = 4

  FpSpread1.ActiveSheet.Cells(2, 0).Value = -1
  FpSpread1.ActiveSheet.Cells(2, 1).Value = 3
  FpSpread1.ActiveSheet.Cells(2, 2).Value = 2
  FpSpread1.ActiveSheet.Cells(2, 3).Value = 1

  ' セル範囲の定義
  Dim data1 As New FarPoint.Win.Spread.Chart.SheetCellRange(FpSpread1.ActiveSheet, 0, 0, 1, 5)
  Dim data2 As New FarPoint.Win.Spread.Chart.SheetCellRange(FpSpread1.ActiveSheet, 1, 0, 1, 5)
  Dim data3 As New FarPoint.Win.Spread.Chart.SheetCellRange(FpSpread1.ActiveSheet, 2, 0, 1, 5)

  ' スタイルを設定
  Dim setting As New FarPoint.Win.Spread.ExcelSparklineSetting()
  setting.ShowMarkers = True
  setting.ShowNegative = True
  setting.NegativeColor = Color.Red
  setting.SeriesColor = Color.Olive

  FpSpread1.ActiveSheet.AddSparkline(data1, New FarPoint.Win.Spread.Model.CellRange(0, 4, 1, 1), FarPoint.Win.Spread.SparklineType.Column, setting)
  FpSpread1.ActiveSheet.AddSparkline(data2, New FarPoint.Win.Spread.Model.CellRange(1, 4, 1, 1), FarPoint.Win.Spread.SparklineType.Line, setting)
  FpSpread1.ActiveSheet.AddSparkline(data3, New FarPoint.Win.Spread.Model.CellRange(2, 4, 1, 1), FarPoint.Win.Spread.SparklineType.Winloss, setting)
End Sub

 

 


© MESCIUS inc. All rights reserved.