ASP.NET如何用OWC绘图控件画统计图表(二)

作者:互联网   出处:控件中国网   2014-11-05 19:19:50   阅读:1

  //指定图表是否需要图例标注
  InsertChart.HasLegend = false;
  InsertChart.HasTitle = true;//为图表添加标题
  InsertChart.Title.Caption = "2006年清清月儿每个月花销流水账";//标题名称
  //为x,y轴添加图示说明
  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 = "数量";
  //添加一个series系列
  InsertChart.SeriesCollection.Add(0);
  //给定series系列的名字
  InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimSeriesNames, +(int)ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName);
  //给定分类
  InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, +(int)ChartSpecialDataSourcesEnum.chDataLiteral, strXdata);
  //给定值
  InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strYdata);
  //输出文件.
  string strAbsolutePath = (Server.MapPath(".")) + "\\ShowData.gif ";
  laySpace.ExportPicture(strAbsolutePath, "GIF", 400, 250);
  //创建GIF文件的相对路径.
  string strRelativePath = "./ShowData.gif";
  //把图片添加到placeholder中,并在页面上显示
  string strImageTag = "";
  this.PlaceHolder1.Controls.Add(new LiteralControl(strImageTag));
  }
  }

  数据库SQL脚本:

  USE [web]
  GO
  /****** 对象: Table [dbo].[Chart] ******/
  SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  CREATE TABLE [dbo].[Chart](
  [id] [int] IDENTITY(1,1) NOT NULL,
  [month] [smallint] NULL,
  [Allcount] [int] NULL
  ) ON [PRIMARY]

  在数据库建好表以后要自己手动假想有12条数据,手动添加,最终结果类似下图:

 

  后台程序说明:

  最关键就是InsertChart.Type = ChartChartTypeEnum.chChartTypeColumnClustered;

  你可以在ChartChartTypeEnum后点出其他方法。如图所示:

 

  下面列出的是其他类型图:

  折线图:

 

  面积图:

 

  条形图:

 

  OWC什么图形都可以画,还能画立体的,请大家自己尝试。

  可以参考OWC手册,具体位置:

  C:\Program Files\Common Files\Microsoft Shared\Web Components\11\2052\OWCVBA11.CHM

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat