Terry's blog

Focus on bigdata and cloud.

博客园 首页 新随笔 联系 订阅 管理

 概述:

    图形和图表是Web上数据表现的很好的形式,在ASP.NET,可以使用Office Web Components (OWC)来创建统计图。Office Web Component (OWC)是包含在Microsoft Office 2000中的一套组件,利用这些组件,我们可以很方便地在浏览器中或者传统的编程环境中进行数据分析和报表。、

 代码:

 1 //创建一个图形容器对象  ChartSpace objCSpace = new ChartSpaceClass();
 2   //在图形容器中增加一个图形对象
 3   ChChart objChart = objCSpace.Charts.Add(0);
 4   //将图形的类型设置为柱状图的一种
 5   objChart.Type = ChartChartTypeEnum.chChartTypePie3D;
 6   //将图形容器的边框颜色设置为白色
 7   objCSpace.Border.Color = "White";
 8 
 9   //显示标题
10   objChart.HasTitle = true;
11   //设置标题内容
12   objChart.Title.Caption = "统计图测试";
13   //设置标题字体的大小
14   objChart.Title.Font.Size = 12;
15   //设置标题为粗体
16   objChart.Title.Font.Bold = true;
17   //设置标题颜色为红色
18   objChart.Title.Font.Color = "Red";
19 
20   //显示图例
21   objChart.HasLegend = true;
22   //设置图例字体大小
23   objChart.Legend.Font.Size = 11;
24   //设置图例位置为底端
25   objChart.Legend.Position = ChartLegendPositionEnum.chLegendPositionBottom;
26 
27   //在图形对象中添加一个系列
28   objChart.SeriesCollection.Add(0);
29   //给定系列的名字
30   objChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimSeriesNames,
31   +(int)ChartSpecialDataSourcesEnum.chDataLiteral, "指标");
32   //给定值
33   objChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
34   +(int)ChartSpecialDataSourcesEnum.chDataLiteral, "10\t40\t58\t55\t44");
35   //增加数据值标签
36   objChart.SeriesCollection[0].DataLabelsCollection.Add();
37   //显示各部分的数值
38   objChart.SeriesCollection[0].DataLabelsCollection[0].HasValue = false;
39   //显示各部分的百分比
40   objChart.SeriesCollection[0].DataLabelsCollection[0].HasPercentage = true;
41 
42 
43   //显示数据,创建GIF文件的相对路径.
44   string FileName = DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString()
45   + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + ".gif";
46   objCSpace.ExportPicture(HttpContext.Current.Server.MapPath("."+ @"test.jpg""jpg"600300);
47  //加载图片 
48             Image1.ImageUrl = Server.MapPath("."+ @"test.jpg";
49
Code
运行结果:
posted on 2008-08-06 10:49  王晓成  阅读(545)  评论(0编辑  收藏  举报