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. windows 定时任务

    创建定时任务 创建定时任务,时间间隔为1min,开始时间为04:00:00,任务名称为backupSchedule,运行当前目录下的copyData.bat脚本 schtasks /create /s ...

  2. mysql分表,分区的区别和联系

    一,什么是mysql分表,分区 什么是分表,从表面意思上看呢,就是把一张表分成N多个小表,具体请看mysql分表的3种方法 什么是分区,分区呢就是把一张表的数据分成N多个区块,这些区块可以在同一个磁盘 ...

  3. c#汉字与编码之间的转换(输出十六进制)

    /******************************************************************/ /*********************** ****** ...

  4. 记:mysql 连接超时解决办法

    错误描述:Timeout in IO operation 原连接字符串为:Server=182.180.50.118;port=3306;Database=test;Uid=root;Pwd=123; ...

  5. Angular2中的host

    要将Angular组件渲染成DOM中的某种东西,你需要在Angular组件中结合一个DOM元素,我们称这些叫host元素. 一个组件可以用以下方式于其host DOM元素进行交互 它可以监听其事件. ...

  6. Codevs 4600 [NOI2015]程序自动分析

    4600 [NOI2015]程序自动分析 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 传送门 题目描述 Description 在实现程序自动分析的过程中,常常需 ...

  7. 嵌入Web资源的方法

    可以将js .图片.css等嵌入Assembly中,这样就不用将文件在aspx中写了,特别适合做自定义控件的时候将控件用到的资源打包. 将文件放到项目的合适路径,比如jpg文件所在路径的namespa ...

  8. wamp配置

    # #localhost # <VirtualHost *:> DocumentRoot "D:/software/wamp/www" ServerName local ...

  9. SQL Trigger(触发器)

    1.触发器对表进行插入.更新.删除的时候会自动执行的特殊存储过程. 2.触发器一般用在check约束更加复杂的约束上面. 3.触发器和普通的存储过程的区别是:触发器是当对某一个表进行操作. 4.upd ...

  10. sql 自身连接

    "select table1.field1, table2.field1 from table table1, table table2 where table1.id=table2.par ...