回复 3楼liunian的帖子
你好,
我通过以下代码实现了Chart底部位置的设定,可以根据以下代码测试,关键代码为:chart.Top = Convert.ToInt32(this.FpSpread1.Height.Value) -this.FpSpread1.ColumnHeader.Height - Convert.ToInt32(chart.Height.Value)-30;
- protected void Page_Load(object sender, EventArgs e)
- {
- if (IsPostBack)
- return;
- //设置数据源
- DataTable dt = new DataTable("Test");
- DataRow dr = default(System.Data.DataRow);
- dt.Columns.Add("名称");
- dt.Columns.Add("数量");
- dr = dt.NewRow();
- dr[0] = "电器";
- dr[1] = 0.2;
- dt.Rows.Add(dr);
- dr = dt.NewRow();
- dr[0] = "服装";
- dr[1] = 0.5;
- dt.Rows.Add(dr);
- dr = dt.NewRow();
- dr[0] = "家具";
- dr[1] = 0.3;
- dt.Rows.Add(dr);
- //设置 BarSeries
- FarPoint.Web.Chart.BarSeries series = new FarPoint.Web.Chart.BarSeries();
- //设置图表展示数据
- series.Values.DataSource = dt;
- series.Values.DataField = dt.Columns[1].ColumnName;
- //使用多样化颜色显示
- series.VaryColors = true;
- //设置 X 轴显示名称
- series.CategoryNames.Add("电器");
- series.CategoryNames.Add("服装");
- series.CategoryNames.Add("家具");
- series.LabelVisible = true;
- //设置 YPlotArea
- FarPoint.Web.Chart.YPlotArea plotArea = new FarPoint.Web.Chart.YPlotArea();
- //设置显示单位为 20%
- //plotArea.YAxes[0].DisplayUnits = 0.5;
- //设置 Y 轴显示为 Percentage
- plotArea.YAxes[0].LabelNumberFormat = "00.0%";
- //设置 YPlotArea 显示位置
- plotArea.Location = new System.Drawing.PointF(0.2F, 0.2F);
- //设置 YPlotArea 大小
- plotArea.Size = new System.Drawing.SizeF(0.6F, 0.6F);
- plotArea.Series.Add(series);
- //设置图例
- LegendArea legend = new LegendArea();
- legend.Location = new PointF(0.98f, 0.5f);
- legend.AlignmentX = 1.0f;
- legend.AlignmentY = 0.5f;
- //设置图表标签
- LabelArea label = new LabelArea();
- label.Text = "产品分布";
- label.Location = new PointF(0.5f, 0.02f);
- label.AlignmentX = 0.5f;
- label.AlignmentY = 0.0f;
- FarPoint.Web.Chart.ChartModel model = new FarPoint.Web.Chart.ChartModel();
- model.PlotAreas.Add(plotArea);
- model.LegendAreas.Add(legend);
- model.LabelAreas.Add(label);
- FarPoint.Web.Spread.Chart.SpreadChart chart = new FarPoint.Web.Spread.Chart.SpreadChart();
- chart.ViewType = ChartViewType.View3D;
- chart.Model = model;
- //30 为下方CommandBar 的高度。
- chart.Top = Convert.ToInt32(this.FpSpread1.Height.Value) -this.FpSpread1.ColumnHeader.Height - Convert.ToInt32(chart.Height.Value)-30;
- FpSpread1.Sheets[0].Charts.Add(chart);
- }
复制代码 |