回复 2楼dof的帖子
版主你好。
我要做的是在form上放置了一个FpSpread表格控件。
然后在cs文件中利用代码绑定数据源。 最后在页面上实现上边想要的效果。
public void PieChart()
{
fpSpread2.Reset();
fpSpread2.ActiveSheet.ColumnHeader.Visible = false;
fpSpread2.ActiveSheet.RowHeader.Visible = false;
DataTable dta = new DataTable();
dta.Columns.Add("aaa", System.Type.GetType("System.String"));
dta.Columns.Add("bbb", System.Type.GetType("System.String"));
dta.Columns.Add("ccc", System.Type.GetType("System.String"));
DataRow dra = dta.NewRow();
dra[0] = "a";
dra[1] = "10";
dra[2] = "15";
dta.Rows.Add(dra);
DataRow dra1 = dta.NewRow();
dra1[0] = "b";
dra1[1] = "20";
dra1[2] = "250";
dta.Rows.Add(dra1);
DataRow dra2 = dta.NewRow();
dra2[0] = "c";
dra2[1] = "30";
dra2[2] = "265";
dta.Rows.Add(dra2);
fpSpread2.ActiveSheet.DataSource = dta;
FarPoint.Win.Chart.PieSeries series2 = new FarPoint.Win.Chart.PieSeries();
series2.SeriesName = "Series 2";
series2.CategoryNames.DataSource = new FarPoint.Win.Spread.Chart.SeriesDataField(fpSpread2, "DataFieldCategoryName", "Sheet1!$A$1A$" + Convert.ToString(dta.Rows.Count), FarPoint.Win.Spread.Chart.SegmentDataType.Text);
if (this.rbtnAmountShell.Checked == true)
{
series2.Values.DataSource = new FarPoint.Win.Spread.Chart.SeriesDataField(fpSpread2, "DataFieldValue", "Sheet1!$B$1B$" + Convert.ToString(dta.Rows.Count));
}
else
{
series2.Values.DataSource = new FarPoint.Win.Spread.Chart.SeriesDataField(fpSpread2, "DataFieldValue", "Sheet1!$C$1C$" + Convert.ToString(dta.Rows.Count));
}
series2.LabelVisible = true;
FarPoint.Win.Chart.PiePlotArea plotArea = new FarPoint.Win.Chart.PiePlotArea();
plotArea.Location = new System.Drawing.PointF(0.2f, 0.2f);
plotArea.Size = new System.Drawing.SizeF(0.6f, 0.6f);
plotArea.Series.AddRange(new FarPoint.Win.Chart.Series[] { series2 });
FarPoint.Win.Chart.LegendArea legend = new FarPoint.Win.Chart.LegendArea();
legend.Location = new PointF(0.0f, 0.0f);
legend.AlignmentX = 0f;
legend.AlignmentY = 0.0f;
FarPoint.Win.Chart.ChartModel model = new FarPoint.Win.Chart.ChartModel();
model.LegendAreas.Add(legend);
model.PlotAreas.Add(plotArea);
FarPoint.Win.Spread.Chart.SpreadChart chart = new FarPoint.Win.Spread.Chart.SpreadChart();
chart.Size = new Size(600, 350);
chart.Location = new Point(0, 0);
chart.Model = model;
chart.Locked = true;
chart.CanMove = FarPoint.Win.Spread.DrawingSpace.Moving.None;
chart.CanSize = FarPoint.Win.Spread.DrawingSpace.Sizing.None;
fpSpread2.ActiveSheet.Charts.Add(chart);
}
3.jpeg
(16.45 KB, 下载次数: 1427)
|