public PlaceHolder PlaceHolder1;
/// </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文件取得设置
//iImageLength = int.Parse(WebConfigurationManager.AppSettings["ShowImageLength"]);
//iImageWidth = int.Parse(WebConfigurationManager.AppSettings["ShowImageWidth"]);
iImageLength = 450;
iImageWidth = 300;
string strImageName = ChartType.ToString() + "_" + Guid.NewGuid().ToString("N") + ".png";
laySpace.ExportPicture(strAbsolutePath + strImageName, "PNG", 450, 300);
//把图片添加到placeholder中,并在页面上显示
string strImageTag = "<IMG WIDTH='450' SRC='" + strRelativePath + strImageName + "'/>";
this.PlaceHolder1.Controls.Add(new LiteralControl(strImageTag));
// return strImageTag;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有