介绍过基础的MSchart知识后,大家应该容易上手写代码了,最起码搞几个饼图柱状图什么的不在话下了。下面我们看看如何在实际项目中写代码。

  1. 柱状图

     1:  string strSQL;   
     2:  DataSet ds = new DataSet();
     3:  Chart1.ChartAreas[0].Name = "chartArea1";
     4:  Chart1.Titles.Add("chartArea1");
     5:  Chart1.Titles[0].Font = new Font("????", 14, FontStyle.Bold);   
     6:  strSQL = "select col1,col2 from Report";   
     7:  ds.Tables.Add(DBSQL.Query(strSQL, 300).Tables[0].Copy());   
     8:  ds.Tables[0].TableName = "chartArea1";
     9:  if(ds.Tables[0].Rows.Count > 0)   
    10:  {
    11:      Chart1.Series[0].Name = "chartArea1";
    12:      Series ser_qqgzjz = Chart1.Series[0];
    13:      ser_qqgzjz.ChartArea = "chartArea1";
    14:       ser_qqgzjz.Points.DataBind(ds.Tables["qqgzjz"].Rows, "col2", "col1", "");
    15:      ser_qqgzjz.IsValueShownAsLabel = true;
    16:      Chart1.ChartAreas["chartArea1"].AxisY.Title = "Person";
    17:      Chart1.ChartAreas["chartArea1"].AxisX.MinorGrid.LineWidth = 0;
    18:      Chart1.ChartAreas["chartArea1"].AxisX.LabelStyle.Angle = -45;
    19:      Chart1.ChartAreas["chartArea1"].AxisX.MajorGrid.LineDashStyle = ChartDashStyle.NotSet;
    20:      Chart1.ChartAreas["chartArea1"].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash;
    21:  }

  2. 双纵坐标(含百分比)
     1:  // chart is your mschart control,srcSeriesName is the name of source series name,destSeriesName  
     2:  // is the name of series you want to add,which is percent series,totalCount is the number 
     3:  // which to caculator the percent  
     4:  protected void TowGrid(Chart chart, string srcSeriesName, string destSeriesName, double totalCount)
     5:  {
     6:      string strChartArea = chart.Series[srcSeriesName].ChartArea;
     7:      chart.Series[srcSeriesName].ChartType = SeriesChartType.Column;
     8:      double total = totalCount;
     9:      Series destSeries = new Series(destSeriesName);
    10:      chart.Series.Add(destSeries);
    11:      destSeries.ChartType = SeriesChartType.Line;
    12:      destSeries.BorderWidth = 3;
    13:      destSeries.ChartArea = chart.Series[srcSeriesName].ChartArea;
    14:      destSeries.YAxisType = AxisType.Secondary;
    15:      chart.ChartAreas[strChartArea].AxisY2.Maximum = 100;
    16:      chart.ChartAreas[strChartArea].AxisY2.Title = "??????%??";
    17:      chart.ChartAreas[strChartArea].AxisY2.TitleFont = new Font("??????", 10);
    18:      destSeries.LabelFormat = "P1";
    19:      chart.ChartAreas[strChartArea].AxisY2.MajorGrid.LineDashStyle = ChartDashStyle.NotSet;
    20:      chart.ChartAreas[strChartArea].AxisX.LabelStyle.IsEndLabelVisible = false;
    21:      double percentage = 0.0;
    22:      foreach (DataPoint pt in chart.Series[srcSeriesName].Points)
    23:      {
    24:        percentage = (pt.YValues[0] * 100.0 / total);
    25:        destSeries.Points.Add(Math.Round(percentage, 2));
    26:      }
    27:      chart.Series[destSeriesName].IsValueShownAsLabel = true;
    28:      chart.Series[destSeriesName].MarkerColor = Color.Red;
    29:      chart.Series[destSeriesName].MarkerBorderColor = Color.MidnightBlue;
    30:      chart.Series[destSeriesName].MarkerStyle = MarkerStyle.Circle;
    31:      chart.Series[destSeriesName].MarkerSize = 8;
    32:      chart.Series[destSeriesName].LabelFormat = "0.#";
    33:    }
    34:  }

    通过以上代码的结合,就能制作出如下效果的图表:

 PS:不少网友遇到横坐标值不能完全显示的问题,只需要修改横坐标的间隔值即可。如:

 chart_ser.ChartAreas[0].AxisX.Interval = 1;
 chart_ser.ChartAreas[0].AxisX.IntervalOffset = 1;

 
 

转载于:https://www.cnblogs.com/tristinjet/archive/2009/11/09/1598981.html

MSChart使用导航之开发相关推荐

  1. bootstrapV4.6.0 - 导航栏开发 (案例篇)

    bootstrapV4.6.0 - 导航栏开发 (案例篇) 经验点: 导航栏背景色 ((全window宽度)); 导航栏字体大小设置: 导航栏背景色设置: 导航栏下拉菜单的下拉效果(click改为ho ...

  2. 地图导航APP开发功能

    地图导航APP开发,地图导航APP开发功能 1.服务平台追踪定位:一部分用户方位感较弱,用户只需打开手机定位服务,APP便会即时表明用户部位信息. 2.路线规划信息:用户应用地图导航APP,则是期望能 ...

  3. 地图导航APP开发作用

    地图导航APP开发,地图导航APP开发作用. 近些年大家生活的节奏持续加速,很多人针对出游造成了比较大要求,但要想在日常生活中进行有关活动需搞好很多的准备工作,终究用户去到生疏地区都要提早了解好行为路 ...

  4. 电子沙盘数字沙盘开发教程第26课:三维数字沙盘M3D GIS导航数据开发代码说明

    电子沙盘开发教程第26课:三维数字沙盘M3D GIS导航数据开发代码说明 SDK中自带了一套 导航系统,用的是比较详细的导航数据,你们懂的,修正了一下在使用互联网服务器时候的一个BUG,请在使用这部分 ...

  5. android开发导航sdk,Android导航SDK开发指南(26页)-原创力文档

    Android 导航SDK 开发指南 一.概述 Android 导航SDK 目前为V1.1 版本,以.jar 形式提供,请广大开发者使用SDK 前务必 在官网申请key,以便全部功能顺利使用. And ...

  6. 云开发地图标记导航 云开发一次性取所有数据

    地图取 elx 表格的经纬度数据,存到云开发数据库里面,然后标记在地图上,点击地图的标记可以实现路线规划,导航,拨打电话. elx数据格式如下: 云开发的数据库不能直接导入elx,所以需要转换为csv ...

  7. 你好,SegmentFault 新导航 【开发手册】; 再见,侧边导航栏

    SegmentFault 在夏季上线了 SegmentFault 5.0 版本,迭代了整个主站的样式,在 8 月的时候上线了面板九宫格(侧边导航栏),整合了部分的入口,方便用户查看笔记.徽章和排行榜等 ...

  8. vue2+vuecli3+elementUI后台管理系列之sidebar导航的开发(五)

    我们接着来实现sidebar的导航菜单布局效果 改造src/layout/components/Sidebar/index.vue <template><div><log ...

  9. AR导航精灵开发复盘

    本文是app"AR导航精灵"的开发复盘总结,您可以在AppStore上搜索到:源代码请参看我的GitHub页面:https://github.com/734843327/AR-na ...

最新文章

  1. 计算机网络各层代表设备
  2. python算法详解豆瓣_豆瓣爬虫实践-python版
  3. 学java需要学c语言吗?
  4. HTTP的请求与响应问题(没有了CSDN,暂时把这里当作论坛了)
  5. zookeeper 四字命令的使用
  6. mysql InnoDB引擎支持hash索引吗
  7. 地理信息系统(GIS)系列——ArcGIS API for JavaScript 3.9(2)
  8. Hadoop原理简介
  9. 学会忘记其实是一种美德
  10. vantfieldlabel样式修改_Vant Field 输入框
  11. 通信笑笑点(2010.08.14)
  12. cmd中mysql的操作语句_cmd命令行数据库操作语句
  13. 使用checkstyle对android代码进行格式检查和格式化(google格式)
  14. 微信发送视频不被压缩的方法
  15. Error response from daemon: Container xxx is not running的解决方法
  16. 小米智能电视怎么投屏
  17. 《计算机网络——自顶向下方法》学习笔记——应用层
  18. API ShowWindow
  19. 如何使用ROS 控制桌面机械手Dobot魔术师?
  20. python练习---大球吃小球游戏

热门文章

  1. Ruby的资源站点和开发工具列表
  2. [导入]Update实现多表更新
  3. java笔记--关于线程同步(7种同步方式)
  4. 26.Azure备份服务器(下)
  5. ajax、offset
  6. Apache Ant自动化脚本
  7. 一群人花费了四年的时间以NASA的数据巨制“月球”
  8. 菜鸟学Java(十一)——GET与POST
  9. MNMBottomPullToRefresh
  10. do while(false)