- ref url : https://www.grapecity.com/en/forums/spread-winforms/sample-code-to-insert-a-sp

 

Sample code to insert a spread chart at run time | Spread for WinForms | Spread Studio | GrapeCity Forums

Discussion of topic Sample code to insert a spread chart at run time in Spread for WinForms forum.

www.grapecity.com

private void button2_Click(object sender, EventArgs e)
{
	object[,] values = {{"ID","Math","LA","Science"},
						{"1",50,25,55},
						{"2",92,24,24},
						{"3",65,70,60},
						{"4",24,26,20},
						{"5",80,26,20}
	};

	this.grdMain.Sheets[1].SetArray(0, 0, values);

	this.InsertChart(this.grdMain, 1);

}

private void InsertChart(FpSpread fps, Int32 charttype)
{
	SheetView sv = fps.Sheets[1];
	if (charttype == 1) // clustereed columns
	{
		BarSeries s1 = new BarSeries();
		s1.SeriesName = sv.Cells[0, 1].Value.ToString();
		s1.Values.DataSource = new SeriesDataField(fps, "Math", "Sheet2!$B$2:$B$6");
		BarSeries s2 = new BarSeries();
		s2.SeriesName = sv.Cells[0, 2].Value.ToString();
		s2.Values.DataSource = new SeriesDataField(fps, "LA", "Sheet2!$C$2:$C$6");
		BarSeries s3 = new BarSeries();
		s3.SeriesName = sv.Cells[0, 3].Value.ToString();
		s3.Values.DataSource = new SeriesDataField(fps, "Science", "Sheet2!$D$2:$D$6");

		ClusteredBarSeries ss = new ClusteredBarSeries();
		ss.Series.Add(s1);
		ss.Series.Add(s2);
		ss.Series.Add(s3);

		YPlotArea yplotarea1 = new YPlotArea();
		yplotarea1.Series.Add(ss);
		SpreadChart chart1 = new SpreadChart();
		chart1.Model.PlotAreas.Add(yplotarea1);

		chart1.Rectangle = new System.Drawing.Rectangle(150, 150, 150, 150);
		chart1.SheetName = "Sheet1";

		// You missed this line of code
		fps.Sheets[0].Charts.Add(chart1);
	}
}
728x90

'Programming Language > C#' 카테고리의 다른 글

UI컴포넌트 Naming  (0) 2021.06.07
C#, TeeChart에 ToolTip 표시하기  (0) 2021.04.01
offline .net 3.5 설치  (0) 2020.07.30
[grapecity/farpoint] ComboBoxCellType 처리.  (0) 2020.07.08
[grapecity/farpoint] fix spread column size  (0) 2020.07.08

+ Recent posts