public PlaceHolder PlaceHolder1; //显示图像的控件

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

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 = ;
//最大值
int iMaxValue = ;
string strXdata = String.Empty;
string strYdata = String.Empty; //为数组赋值
for (int i = ; i < dbDtViewWrk.Rows.Count; i++)
{
ItemsName[i] = dbDtViewWrk.Rows[i][].ToString(); //要统计的字段名字
ItemsCount[i] = dbDtViewWrk.Rows[i][].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 > )
{
iUnit = iMaxValue / ;
}
//创建ChartSpace对象来放置图表
ChartSpace laySpace = new ChartSpaceClass(); //在ChartSpace对象中添加图表
ChChart InsertChart = laySpace.Charts.Add(); //底座颜色
InsertChart.PlotArea.Interior.Color = "white"; //指定绘制图表的类型。类型可以通过OWC.ChartChartTypeEnum枚举值得到
InsertChart.Type = ChartType;//柱形图 //指定图表是否需要图例标注
InsertChart.HasLegend = true;
InsertChart.BarWidth = ;
InsertChart.Legend.Position = ChartLegendPositionEnum.chLegendPositionBottom; InsertChart.HasTitle = true;//为图表添加标题
InsertChart.Title.Caption = strTitle;//标题名称 //为x,y轴添加图示说明
if (ChartType.ToString().IndexOf("ChartTypePie") == -)
{
InsertChart.Axes[].Font.Size = ; //X轴 InsertChart.Axes[].Font.Size = ; //Y轴
InsertChart.Legend.Font.Size = ;
InsertChart.Axes[].HasTitle = true;
InsertChart.Axes[].Title.Caption = "";//月份
InsertChart.Axes[].HasTitle = true;
//InsertChart.Axes[1].Scaling.SplitMinimum = 200;
InsertChart.Axes[].Title.Caption = "数量";
InsertChart.Axes[].MajorUnit = iUnit; //刻度单位设置
InsertChart.Axes[].Scaling.Minimum = ;//最小刻度=0
} //添加一个series系列
InsertChart.SeriesCollection.Add(); //给定series系列的名字
InsertChart.SeriesCollection[].SetData(ChartDimensionsEnum.chDimSeriesNames, +(int)ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName); //给定分类
strXdata = strXdata.Substring(, strXdata.Length - );
InsertChart.SeriesCollection[].SetData(ChartDimensionsEnum.chDimCategories, +(int)ChartSpecialDataSourcesEnum.chDataLiteral, strXdata); //给定值
strYdata = strYdata.Substring(, strYdata.Length - );
InsertChart.SeriesCollection[].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strYdata); //添加标签
ChDataLabels dls = InsertChart.SeriesCollection[].DataLabelsCollection.Add();
if (ChartType.ToString().IndexOf("ChartTypePie") != -)
{
dls.Position = ChartDataLabelPositionEnum.chLabelPositionCenter;
dls.HasPercentage = false;
//dls.HasValue = false;
dls.HasCategoryName = false;
//指定图表是否需要图例标注
InsertChart.HasLegend = true;
InsertChart.Legend.Position = ChartLegendPositionEnum.chLegendPositionBottom;
} //输出文件.
int iImageLength = ;
int iImageWidth = ; //从Config文件取得设置
//iImageLength = int.Parse(WebConfigurationManager.AppSettings["ShowImageLength"]);
//iImageWidth = int.Parse(WebConfigurationManager.AppSettings["ShowImageWidth"]);
iImageLength = ;
iImageWidth = ; string strImageName = ChartType.ToString() + "_" + Guid.NewGuid().ToString("N") + ".png";
laySpace.ExportPicture(strAbsolutePath + strImageName, "PNG", , ); //把图片添加到placeholder中,并在页面上显示
string strImageTag = "<IMG WIDTH='450' SRC='" + strRelativePath + strImageName + "'/>"; this.PlaceHolder1.Controls.Add(new LiteralControl(strImageTag));
// return strImageTag;
}

使用C#画图(饼图折线图)的更多相关文章

  1. c#画图之折线图

    public JsonResult DrawLineChart() { // 预置颜色 List<Color> colors = new List<Color>() { Col ...

  2. 用python的matplotlib根据文件里面的数字画图像折线图

    思路:用open打开文件,再用a=filename.readlines()提取每行的数据作为列表的值,然后传递列表给matplotlib并引入对应库画出图像 代码实现:import matplotli ...

  3. 利用python进行折线图,直方图和饼图的绘制

    我用10个国家某年的GDP来绘图,数据如下: labels   = ['USA', 'China', 'India', 'Japan', 'Germany', 'Russia', 'Brazil', ...

  4. python操作Excel、openpyxl 之图表,折线图、饼图、柱状图等

    一.准备 需要模块: from openpyxl.workbook import Workbook from openpyxl.chart import Series,LineChart, Refer ...

  5. C# WinForm开发系列之c# 通过.net自带的chart控件绘制饼图,柱形图和折线图的基础使用和扩展

    一.需要实现的目标是: 1.将数据绑定到pie的后台数据中,自动生成饼图. 2.生成的饼图有详细文字的说明. 1.设置chart1的属性Legends中默认的Legend1的Enable为false: ...

  6. 安卓图表引擎AChartEngine(三) - 示例源码折线图、饼图和柱状图

    折线图: package org.achartengine.chartdemo.demo.chart; import java.util.ArrayList; import java.util.Lis ...

  7. 百度推出的echarts,制表折线图柱状图饼图等的超级工具(转)

    一.简介: 1.绘制数据图表,有了它,想要网页上绘制个折线图.柱状图,从此easy. 2.使用这个百度的echarts.js插件,是通过把图片绘制在canvas上在显示在页面上. 官网对echarts ...

  8. java利用JFreeChart实现各种数据统计图(柱形图,饼图,折线图)

    最近在做数据挖掘的课程设计,需要将数据分析的结果很直观的展现给用户,这就要用到数据统计图,要实现这个功能就需要几个第三方包了: 1.       jfreechart-1.0.13.jar 2.    ...

  9. JFreeChart 图表生成实例(饼图、柱状图、折线图、时序图)

    import java.awt.BasicStroke; import java.awt.Color; import java.io.FileOutputStream; import java.io. ...

随机推荐

  1. SQL Server调优系列基础篇 - 子查询运算总结

    前言 前面我们的几篇文章介绍了一系列关于运算符的介绍,以及各个运算符的优化方式和技巧.其中涵盖:查看执行计划的方式.几种数据集常用的连接方式.联合运算符方式.并行运算符等一系列的我们常见的运算符.有兴 ...

  2. php注册登录时生成的验证码

    http://blog.sina.com.cn/s/blog_8173443e01012l82.html 记得我学php时第一件事就是研究登陆注册.当然,登陆少不了验证码.两年过去了,昨天突然想用个验 ...

  3. HOOK函数(一)——进程内HOOK

    什么是HOOK呢?其实很简单,HOOK就是对Windows消息进行拦截检查处理的一个函数.在Windows的消息机制中,当用户产生消息时,应用程序通过调用GetMessage函数取出消息,然后把消息放 ...

  4. ubuntu 安装 fcitx

    安装fcitx (1)添加ppa源 sudo add-apt-repository ppa:fcitx-team/nightly 或 sudo add-apt-repository ppa:fcitx ...

  5. linq 多条件查询 where 拼接+分页

    首先定义一个静态类 public static class QueryAssembly { /// <summary> /// 返回true /// </summary> // ...

  6. OC加强-day03

    #program mark - 0_18 分类的使用注意 [掌握] 1.分类的作用 作用:讲一个类分为多个模块,将相似功能的方法写在同一个模块中,方便我们后面代码的维护 "强调 1.分类中只 ...

  7. js生成动态日历

    效果图:   看代码: <html> <head> <title>动态日历</title> <style type="text/css& ...

  8. Codevs 4560 NOIP2015 D2T2 子串

    > 4560 NOIP2015 D2T2 子串 时间限制: 1 s 空间限制: 128000 KB 题目等级:黄金 Gold 题目描述 Description 有两个仅包含小写英文字母的字符串A ...

  9. 操作系统之进程篇(4)--经典进程间通信(IPC)问题

    1. 哲学家进餐问题: 问题描述: 五个哲学家在一个圆桌上进餐,每人的面前放了一盘意大利面,两个盘子之间有一个叉子,但是由于盘子里面的面条十分光滑,需要两个叉子才能进行就餐行为.餐桌的布局如下图所示: ...

  10. CentOS6.6源码编译升级GCC至4.8.2

    升级前提 源码编译需要至少要有一个可用的gcc编译器. 可以用过yum自动安装或者手动下载rpm包安装. 通过yum可以看到至少需要下面这些安装包,所以可以到许多rpm package站点中搜索下载相 ...