zoukankan      html  css  js  c++  java
  • MSChart绘图控件中折线图和柱形图画法

    首先在前台拖入一个名为chart1的MSChart控件

            
    //折线图
           string strLegend = "Legend1"; Legend lg = new Legend(strLegend); lg.IsDockedInsideChartArea = false; lg.TitleAlignment = System.Drawing. StringAlignment.Center; chart1.Legends.Add(lg); ChartArea ca = new ChartArea(); ca.AxisX.MajorGrid.Enabled = false; ca.AxisX.MajorTickMark.Enabled = false; ca.AxisY.MajorGrid.LineDashStyle = ChartDashStyle.NotSet; int index = 1; Series MyScore = new Series( "我的得分" ); MyScore.ChartType = SeriesChartType.Line; MyScore.Legend = "Legend1"; MyScore.ChartArea = "ChartArea1"; MyScore.BorderWidth = 40; Series HighScore = new Series( "最高分" ); HighScore.ChartType = SeriesChartType.Line; HighScore.Legend = "Legend1"; HighScore.ChartArea = "ChartArea1"; MyScore.BorderWidth = 40; Series AvgScore = new Series( "平均分" ); AvgScore.ChartType = SeriesChartType.Line; AvgScore.Legend = "Legend1"; AvgScore.ChartArea = "ChartArea1"; MyScore.BorderWidth = 40; foreach (DataRow dr in m_table.Rows) { DataPoint dp; if (dr["MyScore" ] == null) continue; dp = new DataPoint (index, Convert.ToDouble(dr["MyScore" ])); dp.AxisLabel = dr[ "Name"].ToString(); dp.Label = Convert.ToInt32(dr["MyScore" ]).ToString(); dp.BorderWidth = 10; dp.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle .Star10; MyScore.Points.Add(dp); dp = new DataPoint (index, Convert.ToDouble(dr["HighScore" ])); dp.AxisLabel = dr[ "Name"].ToString(); dp.Label = Convert.ToInt32(dr["HighScore" ]).ToString(); dp.BorderWidth = 10; dp.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle .Star10; HighScore.Points.Add(dp); dp = new DataPoint (index, Convert.ToDouble(dr["AvgScore" ])); dp.AxisLabel = dr[ "Name"].ToString(); dp.Label = Convert.ToInt32(dr["AvgScore" ]).ToString(); dp.BorderWidth = 10; dp.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle .Star10; AvgScore.Points.Add(dp); index++; } chart1.Series.Add(MyScore); chart1.Series.Add(HighScore); chart1.Series.Add(AvgScore); chart1.ChartAreas.Add(ca);
             
    //柱形图
              string
    strLegend = "Legend1" ; Legend lg = new Legend(strLegend); lg.IsDockedInsideChartArea = false; lg.TitleAlignment = System.Drawing.StringAlignment .Center; chart1.Legends.Add(lg); ChartArea ca = new ChartArea(); ca.AxisX.MajorGrid.Enabled = false; ca.AxisX.MajorTickMark.Enabled = false; ca.AxisY.MajorGrid.LineDashStyle = ChartDashStyle.NotSet; int index = 1; foreach (DataRow dr in dt.Rows) { Series s = new Series(dr["CourseTermName" ].ToString()); s.ChartType = SeriesChartType.Column; s.Legend = "Legend1"; s.ChartArea = "ChartArea1"; DataPoint dp; dp = new DataPoint (index, Convert.ToDouble(dr["Score" ])); dp.AxisLabel = dr[ "CourseTermName"].ToString(); dp.Label = Convert.ToInt32(dr["Score" ]).ToString(); dp.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle .Star10; s.Points.Add(dp); chart1.Series.Add(s); index++; } chart1.ChartAreas.Add(ca);
    设置序列的BorderWidth可以改变线条的粗细,它是一个int值,值越大,线条越粗;

    设置序列的MarkerStyle可以 显示出数据点标记,它是一个枚举,有多个样式,圆点、三角、矩形什么的,甚至可以通过MarkerImage来指定一个图形作为数据点,属性方面可以通过 MarkerSize和MarkerBorderWidth来指定数据点大小,MarkerColor和MarkerBorderColor来指定数据点 颜色。

    希望对大家有帮助。以上都是我在项目中实现过的。

  • 相关阅读:
    configure: error: no acceptable cc found in $PATH
    SQL server的错误日志导致服务器C盘满
    域名/IP 正则表达式
    rpm 基本命令
    VB TO C#
    yum 的基本操作
    在服务器上怎么检查一个网站的在线连接数有多大。
    MSSQL2005不能连接远程有非法字符密码的数据库
    按账目类型和日期查看账目
    梦断代码读书笔记(二)
  • 原文地址:https://www.cnblogs.com/lzgeveryday/p/4315785.html
Copyright © 2011-2022 走看看