• Dev之 ChartControl的简单使用


    在这里,就用DataTable做个例子

    //表结构

    DataTable newdtb = new DataTable();
    newdtb.Columns.Add("Id", typeof(int));
    newdtb.Columns.Add("ProName", typeof(string));
    newdtb.Columns.Add("ProPrice", typeof(decimal));
    newdtb.Columns.Add("Trade_Date", typeof(string));
    newdtb.Columns["Id"].AutoIncrement = true;

    //表记录

    Random ran = new Random();
     for (int i = 1; i < 10; i++)
     {

           int RandKey = ran.Next(10, 9999);//10~9999之间的数
           decimal dBase = Convert.ToDecimal(ran.NextDouble());//0~1之间的任意数
           DataRow newRow = newdtb.NewRow();
           newRow["Trade_Date"] = i.ToString() + "月";
           newRow["ProPrice"] = Convert.ToDecimal((RandKey * dBase).ToString("0.0#"));
           newdtb.Rows.Add(newRow);
     }
    this.chartControl1.Series.Clear();

    //新建Series
    Series sr = new Series("资金统计", ViewType.Line);//名称与图标的类型

    //设置Series样式
    sr.ArgumentScaleType = ScaleType.Qualitative;//定性的

    sr.ValueScaleType = ScaleType.Numerical;//数字类型

    sr.PointOptions.PointView = PointView.ArgumentAndValues;//显示表示的信息和数据

    sr.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent;//用百分比表示

    sr.PointOptions.ValueNumericOptions.Precision = 0;//百分号前面的数字不跟小数点

    //绑定数据源
    sr.DataSource = newdtb.DefaultView;//newdtb是获取到的数据(可以是数据库中的表,也可以是DataTable)


    sr.ArgumentDataMember = "Trade_Date";//绑定的文字信息(名称)(坐标横轴)


    sr.ValueDataMembers[0] = "ProPrice";//绑定的值(数据)(坐标纵轴)

     //样式
    sr.View.Color = Color.Red;//颜色

    //添加到统计图上
    this.chartControl1.Series.Add(sr);

    //图例设置
    SimpleDiagram3D diagram = new SimpleDiagram3D();


    diagram.RuntimeRotation = true;


    diagram.RuntimeScrolling = true;


    diagram.RuntimeZooming = true;


    //设置图表标题
    ChartTitle ct = new ChartTitle();


    ct.Text = "神马公司资金统计图";


    ct.TextColor = Color.Black;//颜色

    ct.Font = new Font("Tahoma", 12);//字体


    ct.Dock = ChartTitleDockStyle.Top;//停靠在上方


    ct.Alignment = StringAlignment.Center;//居中显示


    this.chartControl1.Titles.Add(ct);


    chartControl1.Legend.Visible = true;//不现实指示图

    效果实现后:

  • 相关阅读:
    Java异常
    JS多个对象添加到一个对象中
    JSON.parse(),JSON.stringify(),jQuery.parseJSON()
    java中什么是序列化和反序列化
    html颜色字体字符代码
    冒泡排序应用
    HTML 速查列表
    html初学(一)
    html初学(二)
    一次、二次、三次指数平滑计算思想及代码
  • 原文地址:https://www.cnblogs.com/dreamflycc/p/2827904.html
Copyright © 2020-2023  润新知