使用OWC生成饼状图和柱状图
来源:互联网 发布:东北大板 知乎 编辑:程序博客网 时间:2024/06/05 22:53
代码在.net 1.1 和OWC 10下面测试通过。
XValue类似于"a\tb\tc\td\t"
YValue类似于"1\t3\t6\t2\t"
一、生成柱状图
二、生成饼状图
XValue类似于"a\tb\tc\td\t"
YValue类似于"1\t3\t6\t2\t"
一、生成柱状图
private void CreatChart()
{
ChartSpaceClass csc = new ChartSpaceClass();
//添加一个图表
ChChart cch = csc.Charts.Add(0);
csc.Border.Color="#7dd4fa";
//OWC10.ChBorder chBorder=(OWC10.ChBorder)csc.Constants;
//指定图表类型
cch.Type = ChartChartTypeEnum.chChartTypeColumnClustered;
//设置特定图表的高度与宽度之比
cch.AspectRatio = 20;
//指定是否显示网格线
cch.Axes[0].HasMajorGridlines = false;
cch.Axes[0].HasMinorGridlines = false;
cch.Axes[1].HasMajorGridlines = false;
cch.Axes[1].HasMinorGridlines = false;
//指定图表是否需要图例
cch.HasLegend = false;
//给定图表标题
cch.HasTitle = false;
//设置x柱文字的大小
cch.Axes[0].Font.Size=20;
cch.Axes[0].Font.Bold=true;
cch.Axes[0].Orientation = (int)ChartLabelOrientationEnum.chLabelOrientationHorizontal;
//图例的位置
//cch.Legend.Position = OWC10.ChartLegendPositionEnum.chLegendPositionBottom;
string type =Request.QueryString["type"]==null?"":Request.QueryString["type"].ToString();
string date=Request.QueryString["date"]==null?"":Request.QueryString["date"].ToString();
string[] strData = esWapper.getChartData(type,date);
//给定需要的数据
//Y轴数据
string YValue = strData[1];
//X轴数据
string XValue = strData[0];
cch.SeriesCollection.Add(0);
//柱体颜色
cch.SeriesCollection[0].Interior.SetPatterned(ChartPatternTypeEnum.chPattern90Percent,"#7dd4fa",
{
ChartSpaceClass csc = new ChartSpaceClass();
//添加一个图表
ChChart cch = csc.Charts.Add(0);
csc.Border.Color="#7dd4fa";
//OWC10.ChBorder chBorder=(OWC10.ChBorder)csc.Constants;
//指定图表类型
cch.Type = ChartChartTypeEnum.chChartTypeColumnClustered;
//设置特定图表的高度与宽度之比
cch.AspectRatio = 20;
//指定是否显示网格线
cch.Axes[0].HasMajorGridlines = false;
cch.Axes[0].HasMinorGridlines = false;
cch.Axes[1].HasMajorGridlines = false;
cch.Axes[1].HasMinorGridlines = false;
//指定图表是否需要图例
cch.HasLegend = false;
//给定图表标题
cch.HasTitle = false;
//设置x柱文字的大小
cch.Axes[0].Font.Size=20;
cch.Axes[0].Font.Bold=true;
cch.Axes[0].Orientation = (int)ChartLabelOrientationEnum.chLabelOrientationHorizontal;
//图例的位置
//cch.Legend.Position = OWC10.ChartLegendPositionEnum.chLegendPositionBottom;
string type =Request.QueryString["type"]==null?"":Request.QueryString["type"].ToString();
string date=Request.QueryString["date"]==null?"":Request.QueryString["date"].ToString();
string[] strData = esWapper.getChartData(type,date);
//给定需要的数据
//Y轴数据
string YValue = strData[1];
//X轴数据
string XValue = strData[0];
cch.SeriesCollection.Add(0);
//柱体颜色
cch.SeriesCollection[0].Interior.SetPatterned(ChartPatternTypeEnum.chPattern90Percent,"#7dd4fa",
"#7dd4fa");
cch.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories,Convert.ToInt32(
cch.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories,Convert.ToInt32(
ChartSpecialDataSourcesEnum.chDataLiteral),XValue) ;
cch.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,Convert.ToInt32(
cch.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,Convert.ToInt32(
ChartSpecialDataSourcesEnum.chDataLiteral),YValue) ;
//以列宽百分比返回或设置相邻分类标志之间的间距
cch.SeriesCollection[0].GapWidth = 80;
// cch.SeriesCollection[0].Points[0].Interior.FillType = ChartFillStyleEnum.chSolid;
// cch.SeriesCollection[0].Points[4].Interior.SetPresetGradient(
// OWC10.ChartGradientStyleEnum.chGradientDiagonalUp,
// OWC10.ChartGradientVariantEnum.chGradientVariantEdges,
// OWC10.ChartPresetGradientTypeEnum.chGradientGoldII);
//cch.SeriesCollection[0].Line.set_Weight(OWC10.LineWeightEnum.owcLineWeightHairline );
//增加数据值标签
cch.SeriesCollection[0].DataLabelsCollection.Add();
cch.SeriesCollection[0].DataLabelsCollection[0].HasValue = true;
//边框颜色
csc.Interior.SetPatterned(ChartPatternTypeEnum.chPattern90Percent,"#A6E3FF","#A6E3FF");
Response.BinaryWrite((Byte[])(csc.GetPicture("png",980, 600)));
//Response.End();
}
//以列宽百分比返回或设置相邻分类标志之间的间距
cch.SeriesCollection[0].GapWidth = 80;
// cch.SeriesCollection[0].Points[0].Interior.FillType = ChartFillStyleEnum.chSolid;
// cch.SeriesCollection[0].Points[4].Interior.SetPresetGradient(
// OWC10.ChartGradientStyleEnum.chGradientDiagonalUp,
// OWC10.ChartGradientVariantEnum.chGradientVariantEdges,
// OWC10.ChartPresetGradientTypeEnum.chGradientGoldII);
//cch.SeriesCollection[0].Line.set_Weight(OWC10.LineWeightEnum.owcLineWeightHairline );
//增加数据值标签
cch.SeriesCollection[0].DataLabelsCollection.Add();
cch.SeriesCollection[0].DataLabelsCollection[0].HasValue = true;
//边框颜色
csc.Interior.SetPatterned(ChartPatternTypeEnum.chPattern90Percent,"#A6E3FF","#A6E3FF");
Response.BinaryWrite((Byte[])(csc.GetPicture("png",980, 600)));
//Response.End();
}
二、生成饼状图
public void ChartPie()
{
//创建一个图形容器对象
OWC10.ChartSpace objCSpace = new OWC10.ChartSpaceClass();
objCSpace.Border.Color="white";
//在图形容器中增加一个图形对象
OWC10.ChChart objChart = objCSpace.Charts.Add(0);
//将图形的类型设置为柱状图的一种
objChart.Type = OWC10.ChartChartTypeEnum.chChartTypePie3D;
//在图形对象中添加一个系列
objChart.SeriesCollection.Add(0);
string type =Request.QueryString["type"]==null?"":Request.QueryString["type"].ToString();
string date=Request.QueryString["date"]==null?"":Request.QueryString["date"].ToString();
string[] strData = esWapper.getChartData(type,date);
//string[] strData = new string[2];
//给定需要的数据
//数据
string YValue = strData[1];
//分类
string XValue = strData[0];
//给定系列的名字
objChart.SeriesCollection[0].SetData (OWC10.ChartDimensionsEnum.chDimCategories,
+ (int)OWC10.ChartSpecialDataSourcesEnum.chDataLiteral, XValue);
//给定值
objChart.SeriesCollection[0].SetData (OWC10.ChartDimensionsEnum.chDimValues,
+ (int)OWC10.ChartSpecialDataSourcesEnum.chDataLiteral, YValue);
objChart.Inclination=55;
//将第三个扇区抽离出来
//Explosion:返回或设置指定饼图或圆环图扇面的分离程度值。有效范围为 0 到 1000。分离程度值等于图表半径的百分比。
//objChart.SeriesCollection[0].Points[2].Explosion = 45;
//增加数据值标签
objChart.SeriesCollection[0].DataLabelsCollection.Add();
//分类名
//objChart.SeriesCollection[0].DataLabelsCollection[0].HasCategoryName=true;
//系列名
//objChart.SeriesCollection[0].DataLabelsCollection[0].HasSeriesName=true;
//设置图例边框颜色
//设置显示图例
objChart.HasLegend=true;
//设置图例的位置,必须先把图例的显示属性设置为true
objChart.Legend.Position = OWC10.ChartLegendPositionEnum.chLegendPositionBottom;
objChart.Legend.Border.Color="#FFFFFF";
objChart.Legend.Font.Size=20;
//显示各部分的数值
objChart.SeriesCollection[0].DataLabelsCollection[0].HasValue = false;
//设置饼状图中字体的大小
objChart.SeriesCollection[0].DataLabelsCollection[0].Font.Size=14;
//显示各部分的百分比
objChart.SeriesCollection[0].DataLabelsCollection[0].HasPercentage = true;
//Response.Write(DateTime.Now.ToLongDateString());
Response.BinaryWrite((Byte[])(objCSpace.GetPicture("gif",800, 500)));
//Response.End();
}
{
//创建一个图形容器对象
OWC10.ChartSpace objCSpace = new OWC10.ChartSpaceClass();
objCSpace.Border.Color="white";
//在图形容器中增加一个图形对象
OWC10.ChChart objChart = objCSpace.Charts.Add(0);
//将图形的类型设置为柱状图的一种
objChart.Type = OWC10.ChartChartTypeEnum.chChartTypePie3D;
//在图形对象中添加一个系列
objChart.SeriesCollection.Add(0);
string type =Request.QueryString["type"]==null?"":Request.QueryString["type"].ToString();
string date=Request.QueryString["date"]==null?"":Request.QueryString["date"].ToString();
string[] strData = esWapper.getChartData(type,date);
//string[] strData = new string[2];
//给定需要的数据
//数据
string YValue = strData[1];
//分类
string XValue = strData[0];
//给定系列的名字
objChart.SeriesCollection[0].SetData (OWC10.ChartDimensionsEnum.chDimCategories,
+ (int)OWC10.ChartSpecialDataSourcesEnum.chDataLiteral, XValue);
//给定值
objChart.SeriesCollection[0].SetData (OWC10.ChartDimensionsEnum.chDimValues,
+ (int)OWC10.ChartSpecialDataSourcesEnum.chDataLiteral, YValue);
objChart.Inclination=55;
//将第三个扇区抽离出来
//Explosion:返回或设置指定饼图或圆环图扇面的分离程度值。有效范围为 0 到 1000。分离程度值等于图表半径的百分比。
//objChart.SeriesCollection[0].Points[2].Explosion = 45;
//增加数据值标签
objChart.SeriesCollection[0].DataLabelsCollection.Add();
//分类名
//objChart.SeriesCollection[0].DataLabelsCollection[0].HasCategoryName=true;
//系列名
//objChart.SeriesCollection[0].DataLabelsCollection[0].HasSeriesName=true;
//设置图例边框颜色
//设置显示图例
objChart.HasLegend=true;
//设置图例的位置,必须先把图例的显示属性设置为true
objChart.Legend.Position = OWC10.ChartLegendPositionEnum.chLegendPositionBottom;
objChart.Legend.Border.Color="#FFFFFF";
objChart.Legend.Font.Size=20;
//显示各部分的数值
objChart.SeriesCollection[0].DataLabelsCollection[0].HasValue = false;
//设置饼状图中字体的大小
objChart.SeriesCollection[0].DataLabelsCollection[0].Font.Size=14;
//显示各部分的百分比
objChart.SeriesCollection[0].DataLabelsCollection[0].HasPercentage = true;
//Response.Write(DateTime.Now.ToLongDateString());
Response.BinaryWrite((Byte[])(objCSpace.GetPicture("gif",800, 500)));
//Response.End();
}
转自:http://www.cnblogs.com/liguiqing/articles/948327.html
- 使用OWC生成饼状图和柱状图
- ASP.NET 2.0中OWC生成柱状图和饼状图
- ASP.NET 2.0中OWC生成柱状图和饼状图
- OWC组件生成柱状图
- ASP.NET 2.0中OWC生成柱状图和饼状图的源代码
- ASP.NET 2.0中OWC生成柱状图和饼状图的源代码
- ASP.NET 2.0中OWC生成柱状图和饼状图的源代码
- ASP.NET 2.0中OWC生成柱状图和饼状图的源代码
- ASP.NET 2.0中OWC生成柱状图和饼状图的源代码
- 如何使用PHP动态生成饼状图、柱状图和折线图
- 如何使用PHP动态生成饼状图、柱状图和折线图
- 使用jfreechart生成柱状图、折线图、和饼状图
- C# 使用OWC生成图表
- 使用JFreeChart生成柱状图和饼图
- OWC 实现 叠加 柱状图
- C#中用GDI+生成饼状图和柱状图
- PHP生成柱状图、饼状图和线性图
- 项目开发 - 使用OWC生成统计图
- 在excel的单元格中设置下拉菜单
- 导图 SQL Server之管理数据库
- HDU 2566 统计硬币
- 暑期训练营中关于《成为职业程序员》的讲座和大家讨论的
- native2ascii工具
- 使用OWC生成饼状图和柱状图
- hdu 2602 Bone Collector【01背包】
- 大家来讨论怎么写概要设计
- styleFloat和cssFloat
- Tomcat 7 的七大新特性
- 导图 SQL Server之数据库对象管理 之 视图管理
- java 中遍历Map的几种方法
- 临时对象与拷贝构造函数
- 通过javascript修改文本框内容后提交后无效