用Infragistics.UltraChart制作柱状图标准代码,共六步!

 using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using Infragistics.UltraChart.Shared.Styles;
using Infragistics.UltraChart.Resources.Appearance;
using Infragistics.UltraChart.Core.Layers;

namespace Test
{
 /// <summary>
 /// Col 的摘要说明。
 /// </summary>
 public class Col : System.Web.UI.Page
 {
  protected Infragistics.WebUI.UltraWebChart.UltraChart UltraChart1;
 
  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
   //step1:Change the ChartType property to "Composite."
   this.UltraChart1.ChartType = ChartType.Composite;
   //step2:Add a ChartArea to the ChartAreas collection.
   ChartArea myChartArea = new ChartArea();
   this.UltraChart1.CompositeChart.ChartAreas.Add(myChartArea);
   //step3:Add some Axes to the ChartArea.
   AxisItem axisX = new AxisItem();
   axisX.OrientationType = AxisNumber.X_Axis;
   axisX.DataType = AxisDataType.String;
   axisX.SetLabelAxisType = SetLabelAxisType.GroupBySeries;
   axisX.Labels.ItemFormatString = "<ITEM_LABEL>";
   axisX.Labels.Orientation = TextOrientation.VerticalLeftFacing;
   AxisItem axisY = new AxisItem();
   axisY.OrientationType = AxisNumber.Y_Axis;
   axisY.DataType = AxisDataType.Numeric;
   axisY.Labels.ItemFormatString = "<DATA_VALUE:0.#>";
   myChartArea.Axes.Add(axisX);
   myChartArea.Axes.Add(axisY);
   //step4:Add some data series to the Series collection.
   NumericSeries seriesA = GetNumericSeriesBound();
   NumericSeries seriesB = GetNumericSeriesUnBound();
   this.UltraChart1.CompositeChart.Series.Add(seriesA);
   this.UltraChart1.CompositeChart.Series.Add(seriesB);
   //step5:Add a chart layer.
   ChartLayerAppearance myColumnLayer = new ChartLayerAppearance();
   myColumnLayer.ChartType = ChartType.ColumnChart;
   myColumnLayer.ChartArea = myChartArea;
   myColumnLayer.AxisX = axisX;
   myColumnLayer.AxisY = axisY;
   myColumnLayer.Series.Add(seriesA);
   myColumnLayer.Series.Add(seriesB);
   this.UltraChart1.CompositeChart.ChartLayers.Add(myColumnLayer);
   //step6:Add a legend to the chart.
   //CompositeLegend myLegend = new CompositeLegend();
   //CompositeLegend a = new CompositeLegend();
   Infragistics.UltraChart.Resources.Appearance.CompositeLegend myLegend = new Infragistics.UltraChart.Resources.Appearance.CompositeLegend();
   //Infragistics.UltraChart.Resources.Appearance.CompositeLegendAppearance myLegend = new CompositeLegendAppearance();
   myLegend.ChartLayers.Add(myColumnLayer);
   myLegend.Bounds = new Rectangle(0, 75, 20, 25);
   myLegend.BoundsMeasureType = MeasureType.Percentage;
   myLegend.PE.ElementType = PaintElementType.Gradient;
   myLegend.PE.FillGradientStyle = GradientStyle.ForwardDiagonal;
   myLegend.PE.Fill = Color.CornflowerBlue;
   myLegend.PE.FillStopColor = Color.Transparent;
   myLegend.Border.CornerRadius = 10;
   myLegend.Border.Thickness = 0;
   this.UltraChart1.CompositeChart.Legends.Add(myLegend);
  }

  #region Web 窗体设计器生成的代码
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {   
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion

  /// <summary>
  /// 创建数据
  /// </summary>
  private DataTable GetData()
  {
   DataTable table = new DataTable();
   table.Columns.Add("Label Column", Type.GetType("System.String"));
   table.Columns.Add("Value Column", Type.GetType("System.Double"));
   table.Columns.Add("Another Value Column", Type.GetType("System.Double"));
   table.Rows.Add(new object[] {"Point A", 1.0, 3.0});
   table.Rows.Add(new object[] {"Point B", 2.0, 2.0});
   table.Rows.Add(new object[] {"Point C", 3.0, 1.0});
   table.Rows.Add(new object[] {"Point D", 4.0, 2.0});
   table.Rows.Add(new object[] {"Point E", 5.0, 3.0});
   return table;
  }
  /// <summary>
  /// 绑定数据,数据库
  /// </summary>
  private NumericSeries GetNumericSeriesBound()
  {
   NumericSeries series = new NumericSeries();
   series.Label = "Series A";
   DataTable table = GetData();
   series.Data.DataSource = table;
   series.Data.LabelColumn = "Label Column";
   series.Data.ValueColumn = "Value Column";
   return series;
  }
  /// <summary>
  /// 绑定数据
  /// </summary>
  private NumericSeries GetNumericSeriesUnBound()
  {
   NumericSeries series = new NumericSeries();
   series.Label = "Series B";
   series.Points.Add(new NumericDataPoint(5.0, "Point A", false));
   series.Points.Add(new NumericDataPoint(4.0, "Point B", false));
   series.Points.Add(new NumericDataPoint(3.0, "Point C", false));
   series.Points.Add(new NumericDataPoint(2.0, "Point D", false));
   series.Points.Add(new NumericDataPoint(1.0, "Point E", false));
   return series;
  }
 }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值