• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

green hand

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

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来指定数据点 颜色。

 

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

posted on 2015-03-05 14:37  green hand  阅读(629)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3