• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >C#教程 > C#画图之饼图折线图的实现方法

C#画图之饼图折线图的实现方法

作者: 字体:[增加 减小] 来源:互联网 时间:2017-05-28

通过本文主要向大家介绍了c#chart控件折线图,c#折线图,c#画折线图,c#绘制折线图,c#chart折线图等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了C#画图之饼图折线图的实现方法,是C#程序设计中非常实用的技巧。分享给大家供大家参考。具体方法分析如下:

显示图像的控件定义如下:

public PlaceHolder PlaceHolder1;

</div>

各个图像的类别名称如下:

PictureType    图形种类    5    chChartTypeBarClustered    簇状条形图    0    NULL

PictureType    图形种类    7    chChartTypeBarClustered3D    三维簇状条形图    0    NULL

PictureType    图形种类    6    chChartTypeBarStacked    堆积条形图    0    NULL

PictureType    图形种类    8    chChartTypeBarStacked3D    三维堆积条形图    0    NULL

PictureType    图形种类    1    chChartTypeColumnClustered    簇状柱形图    0    NULL

PictureType    图形种类    3    chChartTypeColumnClustered3D    三维簇状柱形图    0    NULL

PictureType    图形种类    2    chChartTypeColumnStacked    堆积柱状图    1    NULL

PictureType    图形种类    4    chChartTypeColumnStacked3D    三维堆积柱形图    0    NULL

PictureType    图形种类    13    chChartTypeLine    折线图    0    NULL

PictureType    图形种类    15    chChartTypeLineMarkers    数据点折线图    0    NULL

PictureType    图形种类    14    chChartTypeLineStacked    堆积折线图    0    NULL

PictureType    图形种类    16    chChartTypeLineStackedMarkers    堆积数据点折线图    0    NULL

PictureType    图形种类    17    chChartTypePie    饼图    1    NULL

PictureType    图形种类    19    chChartTypePie3D    三维饼图    0    NULL

PictureType    图形种类    18    chChartTypePieExploded    分离型饼图    0    NULL

PictureType    图形种类    20    chChartTypePieExploded3D    分离型三维饼图    0    NULL

PictureType    图形种类    9    chChartTypeSmoothLine    平滑线图    0    NULL

PictureType    图形种类    10    chChartTypeSmoothLineMarkers    数据点平滑线图    0    NULL

PictureType    图形种类    11    chChartTypeSmoothLineStacked    堆积平滑线图    0    NULL

PictureType    图形种类    12    chChartTypeSmoothLineStackedMarkers    堆积数据平滑线图    0    NULL

取图像的方法如下:

/// </summary>
/// <param name="dbDtViewWrk">传递的数据</param>
/// <param name="strAbsolutePath">绝对路径</param>
/// <param name="strRelativePath">相对路径</param>
/// <param name="ChartType">要画的图格式(饼图或者折线图等)</param>
/// <param name="strTitle">统计名称</param>
public void PaintToImage(DataTable dbDtViewWrk, string strAbsolutePath, string strRelativePath, ChartChartTypeEnum ChartType, string strTitle)
{
  string strSeriesName = "图例";
  //存放项目
  string[] ItemsName = new string[dbDtViewWrk.Rows.Count];
  //存放数据
  string[] ItemsCount = new string[dbDtViewWrk.Rows.Count];
  //刻度单位
  int iUnit = 1;
  //最大值
  int iMaxValue = 0;
  string strXdata = String.Empty;
  string strYdata = String.Empty;
  
 //为数组赋值
 for (int i = 0; i < dbDtViewWrk.Rows.Count; i++)
 {
   ItemsName[i] = dbDtViewWrk.Rows[i][0].ToString(); //要统计的字段名字
   ItemsCount[i] = dbDtViewWrk.Rows[i][5].ToString();//要统计的字段数据
 }
  //为x轴指定特定字符串,以便显示数据
  // string strXdata = String.Empty;
  foreach (string strData in ItemsName)
  {
 strXdata += strData + "\t";
  }
  // string strYdata = String.Empty;
  //为y轴指定特定的字符串,以便与x轴相对应
  foreach (string strValue in ItemsCount)
  {
 strYdata += strValue + "\t";
 if (int.Parse(strValue) > iMaxValue)
 {
   iMaxValue = int.Parse(strValue);
 }
  }
  if (iMaxValue > 20)
  {
 iUnit = iMaxValue / 10;
  }
  //创建ChartSpace对象来放置图表
  ChartSpace laySpace = new ChartSpaceClass();
  
  //在ChartSpace对象中添加图表
  ChChart InsertChart = laySpace.Charts.Add(0);
  
  //底座颜色
  InsertChart.PlotArea.Interior.Color = "white";

  //指定绘制图表的类型。类型可以通过OWC.ChartChartTypeEnum枚举值得到
  InsertChart.Type = ChartType;//柱形图


  //指定图表是否需要图例标注
  InsertChart.HasLegend = true;
  InsertChart.BarWidth = 0;
  InsertChart.Legend.Position = ChartLegendPositionEnum.chLegendPositionBottom;

  InsertChart.HasTitle = true;//为图表添加标题
  InsertChart.Title.Caption = strTitle;//标题名称

  //为x,y轴添加图示说明
  if (ChartType.ToString().IndexOf("ChartTypePie") == -1)
  {
 InsertChart.Axes[0].Font.Size = 11; //X轴

 InsertChart.Axes[1].Font.Size = 11; //Y轴
 InsertChart.Legend.Font.Size = 11;
 InsertChart.Axes[0].HasTitle = true;
 InsertChart.Axes[0].Title.Caption = "";//月份
 InsertChart.Axes[1].HasTitle = true;
 //InsertChart.Axes[1].Scaling.SplitMinimum = 200;
 InsertChart.Axes[1].Title.Caption = "数量";
 InsertChart.Axes[1].MajorUnit = iUnit; //刻度单位设置
 InsertChart.Axes[1].Scaling.Minimum = 0;//最小刻度=0
  }

  //添加一个series系列
  InsertChart.SeriesCollection.Add(0);
  
  //给定series系列的名字
  InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimSeriesNames, +(int)ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName);

  //给定分类
  strXdata = strXdata.Substring(0, strXdata.Length - 1);
  InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, +(int)ChartSpecialDataSourcesEnum.chDataLiteral, strXdata);

  //给定值
  strYdata = strYdata.Substring(0, strYdata.Length - 1);
  InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strYdata);

  //添加标签
  ChDataLabels dls = InsertChart.SeriesCollection[0].DataLabelsCollection.Add();
  if (ChartType.ToString().IndexOf("ChartTypePie") != -1)
  {
 dls.Position = ChartDataLabelPositionEnum.chLabelPositionCenter;
 dls.HasPercentage = false;
 //dls.HasValue = false;
 dls.HasCategoryName = false;
 //指定图表是否需要图例标注
 InsertChart.HasLegend = true;
 InsertChart.Legend.Position = ChartLegendPositionEnum.chLegendPositionBottom;
  }

  //输出文件.
  int iImageLength = 0;
  int iImageWidth = 0;

  //从Config文件取得设置
  //iImageLeng



 
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • C#画图之饼图折线图的实现方法

相关文章

  • 2017-05-28C#实现关闭其他程序窗口或进程代码分享
  • 2017-05-28C#连接mysql数据库完整实例
  • 2017-05-28C#判断多个文本框是否为空的方法
  • 2017-05-28WinForm开发中屏蔽WebBrowser脚本错误提示的方法
  • 2017-05-28c#对list排序示例
  • 2017-05-28C#实现XML与实体类之间相互转换的方法(序列化与反序列化)
  • 2017-05-28C#遍历得到checkboxlist选中值和设置选中项的代码
  • 2017-05-28解析C#彩色图像灰度化算法的实现代码详解
  • 2017-05-28深入IComparable与IComparer的排序实例详解
  • 2017-05-28用.NET创建Windows服务的方法第1/2页

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • C#的四个基本技巧
    • WinForm中快捷键与组合按键的设置方法
    • C#提高编程能力的50个要点总结
    • C#中JavaScriptSerializer帮助类用法实例
    • C#几种截取字符串的方法小结
    • C#使用控制台列出当前所有可用的打印机列表
    • 理解C#中的事件
    • C#中的两种debug方法介绍
    • 基于WebRequest.RegisterPrefix的使用详解
    • C#实现treeview绑定的方法

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有