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. Use excel Macro export data from database

    Sub DownLoadMacro() '定义过程名称 Dim i As Integer, j As Integer, sht As Worksheet 'i,j为整数变量:sht 为excel工作表 ...

  2. Java I/O重定向

    1.输入重定向 命令行:java [java类文件] < [输入文件路径名] 代码:InputStream inputStream = new FileInputStream(          ...

  3. mysql的分区技术

    一.概述 当 MySQL的总记录数超过了100万后,会出现性能的大幅度下降吗?答案是肯定的,但是,性 能下降>的比率不一而同,要看系统的架构.应用程序.还有>包括索引.服务器硬件等多种因素 ...

  4. 怎样区分JQuery对象和Dom对象 常用的写法

    第一步,http://www.k99k.com/jQuery_getting_started.html 第二步,新手先仔细得全部看一遍jQuery的选择器,很重要!!! (http://shawphy ...

  5. 转JSONObject put,accumulate,element的区别

        public Object put (Object key, Object value) 将value映射到key下.如果此JSONObject对象之前存在一个value在这个key下,当前的 ...

  6. C++指针学习笔记

    本文参考http://www.prglab.com/cms/pages/c-tutorial/advanced-data/pointers.php 1.存储其它变量地址的变量(如下面例子中的addre ...

  7. 访问Access数据库(有多个数据库时 体现多态)

    如果想编写单机版MIS.小型网站等对数据库性能要求不高的系统,又不想安装SQLServer,可以使用Access(MDAC),只要一个mdb文件就可以了.使用Access创建mdb文件,建表.OleD ...

  8. 【实习记】2014-09-26恢复linux下误删的ntfs盘中的文件

        情景,ubuntu下把NTFS格式的盘中的“实习记”文件夹彻底删除了,追毁莫及,粗心觉不是一件好的事情. linux下回复ntfs盘下的文件不能用ext3grep,而使用debugfs命令实在 ...

  9. SQLite学习第02天:数据类型

    参考资料:http://www.w3cschool.cc/sqlite/sqlite-data-types.html 在SQLite中,数据类型的概念看起来很模糊,刚开始接触感觉跟C语言提供的数据类型 ...

  10. Sumbline编译Less

    Less教程 Sublime Text 2的Less2Css插件介绍与安装 网址 http://fdream.net/blog/article/783.aspx 如果出现node.exe不是内部命令的 ...