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. PAT_1016 部分A+B

    问题描述: 正整数A的“DA(为1位整数)部分”定义为由A中所有DA组成的新整数PA.例如:给定A = 3862767,DA = 6,则A的“6部分”PA是66,因为A中有2个6. 现给定A.DA.B ...

  3. 解决UIScrollView 的点击事件

    目前有两种方法 第一种 通过 Category 扩展 UIScrollView 对象,添加触摸事件,(不建议,后续扩展不方便)代码如下 @implementation UIScrollView (Ex ...

  4. 无刷新删除 Ajax,JQuery

    1.数据库用上面的,增加一个 DeleteById 的SQL方法 delete from T_Posts where Id = @Original_Id 2.设置处理页面 delete.ashx pu ...

  5. linux中python环境搭建及升级后yum不可用解决方案

    1.1 LinuxCentOS 为例.1.1.1 升级 Python(1) 下载 Python 版本$ wget https://www.python.org/ftp/python/2.7.11/Py ...

  6. ubuntu 安装flash插件

    参考文献: http://wiki.debian.org.hk/w/Install_Flash_Player_with_APTapt-get install adobe-flashplugin

  7. js禁止高频率连续点击思路

    1.类似react的数据流,点击之后立即设置值为空,当返回值后才可以点击 2.设置定时器,每次进入之前先清空掉定时器,然后开启定时器 <main> <div id="me& ...

  8. 网站开发常用jQuery插件总结(五)滚动条插件nanoscroller

    网站在展示信息时,如果信息量过大,解决方法主要有三种.1.分页,将信息分页显示.2.整页显示,但是页面过长,影响浏览体验.3.使用滚动条,而默认滚动条样式太单一,用户体验不友好.所以我们需要美化滚动条 ...

  9. 微信公众号-加解密数据demo坑

    demo里面的MsgSignature作为url参数一部分了,demo也不更新下 坑爹的微信! 解密信息部分 include_once "wxBizMsgCrypt.php"; $ ...

  10. asp.net core 认证及简单集群

    众所周知,在Asp.net WebAPI中,认证是通过AuthenticationFilter过滤器实现的,我们通常的做法是自定义AuthenticationFilter,实现认证逻辑,认证通过,继续 ...