GrapeCity SPREAD for Windows Forms 12.0J サンプルコード集 > チャート > チャートを削除する |
Removeメソッドにて対象のチャートを指定することで削除できます。
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.BarSeries series1 = new FarPoint.Win.Chart.BarSeries(); 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.BarSeries series2 = new FarPoint.Win.Chart.BarSeries(); 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.BarSeries series3 = new FarPoint.Win.Chart.BarSeries(); 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.ClusteredBarSeries clbar = new FarPoint.Win.Chart.ClusteredBarSeries(); clbar.Series.AddRange(new FarPoint.Win.Chart.BarSeries[] { series1, series2, series3 }); 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(clbar); // ラベルを設定します 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.ChartName = "barchart"; chart.Size = new Size(400, 200); chart.Location = new Point(3, 130); chart.Model = model; // シートにSPREADチャートを追加します fpSpread1.Sheets[0].Charts.Add(chart); } private void button1_Click(object sender, EventArgs e) { // シート上のチャートオブジェクトを取得します FarPoint.Win.Spread.Chart.SpreadChart cht = new FarPoint.Win.Spread.Chart.SpreadChart(); cht = fpSpread1.Sheets[0].Charts["barchart"]; // チャートを削除します fpSpread1.Sheets[0].Charts.Remove(cht); }
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.BarSeries() 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.BarSeries() 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.BarSeries() 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 clbar As New FarPoint.Win.Chart.ClusteredBarSeries() clbar.Series.AddRange(New FarPoint.Win.Chart.BarSeries() {series1, series2, series3}) 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(clbar) ' ラベルを設定します 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.ChartName = "barchart" chart.Size = New Size(400, 200) chart.Location = New Point(3, 130) chart.Model = model ' シートにSPREADチャートを追加します FpSpread1.Sheets(0).Charts.Add(chart) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' シート上のチャートオブジェクトを取得します Dim cht As New FarPoint.Win.Spread.Chart.SpreadChart cht = FpSpread1.Sheets(0).Charts("barchart") ' チャートを削除します FpSpread1.Sheets(0).Charts.Remove(cht) End Sub