首先下载owc COM组件
注册owc
在工程中添加 C\Program Files\Common Files\Microsoft Shared\Web Components\ 文件下的owcdll引用
在工程中添加
using OWC
开始coding 举例如下
public class ChartFactory { public ChartFactory()
{ InitTypeMap()// // TODO 在此处添加构造函数逻辑// } protected SystemWebUIWebControlsImage imgHondaLineupprivate string[] chartCategoriesArrprivate string[] chartValuesArrprivate OWCChartChartTypeEnum chartType = OWCChartChartTypeEnumchChartTypeColumnD//默认值private static Hashtable chartMap = new Hashtable()private static string chartTypeCh = 垂直柱状图 private static string chartTitle =
private void InitTypeMap()
{ chartMapClear()OWCChartChartTypeEnum[] chartTypes = new OWCChartChartTypeEnum[]{ ChartChartTypeEnumchChartTypeColumnClusteredChartChartTypeEnumchChartTypeColumnDChartChartTypeEnumchChartTypeBarClusteredChartChartTypeEnumchChartTypeBarDChartChartTypeEnumchChartTypeAreaChartChartTypeEnumchChartTypeAreaDChartChartTypeEnumchChartTypeDoughnutChartChartTypeEnumchChartTypeLineStackedChartChartTypeEnumchChartTypeLineDChartChartTypeEnumchChartTypeLineMarkersChartChartTypeEnumchChartTypePieChartChartTypeEnumchChartTypePieD
ChartChartTypeEnumchChartTypeRadarSmoothLineChartChartTypeEnumchChartTypeSmoothLine}
string[] chartTypesCh = new string [] {垂直柱状统计图D垂直柱状统计图水平柱状统计图D水平柱状统计图区域统计图D区域统计图中空饼图折线统计图D折线统计图折线带点统计图饼图D饼图网状统计图弧线统计图}
for(int i=i<chartTypesLengthi++)
{ chartMapAdd(chartTypesCh[i]chartTypes[i])} public ChartSpaceClass BuildCharts ()
{ string chartCategoriesStr = StringJoin (\t chartCategoriesArr)string chartValuesStr = StringJoin (\t chartValuesArr)
OWCChartSpaceClass oChartSpace = new OWCChartSpaceClass ()
// ——// Give pie and doughnut charts a legend on the bottom For the rest of // them let the control figure it out on its own // ——
chartType = (ChartChartTypeEnum)chartMap[chartTypeCh]
if (chartType == ChartChartTypeEnumchChartTypePie || chartType == ChartChartTypeEnumchChartTypePieD || chartType == ChartChartTypeEnumchChartTypeDoughnut)
{ oChartSpaceHasChartSpaceLegend = trueoChartSpaceChartSpaceLegendPosition = ChartLegendPositionEnumchLegendPositionBottom}
oChartSpaceBorderColor = blueoChartSpaceChartsAdd()oChartSpaceCharts[]HasTitle = trueoChartSpaceCharts[]Type = chartTypeoChartSpaceCharts[]ChartDepth = oChartSpaceCharts[]AspectRatio = oChartSpaceCharts[]TitleCaption = chartTitleoChartSpaceCharts[]TitleFontBold = true
oChartSpaceCharts[]SeriesCollectionAdd()oChartSpaceCharts[]SeriesCollection[]DataLabelsCollectionAdd ()
// ——// If youre charting a pie or a variation thereof percentages make a lot // more sense than values……
// ——
if (chartType == ChartChartTypeEnumchChartTypePie || chartType == ChartChartTypeEnumchChartTypePieD || chartType == ChartChartTypeEnumchChartTypeDoughnut)
{ oChartSpaceCharts[]SeriesCollection[]DataLabelsCollection[]HasPercentage = trueoChartSpaceCharts[]SeriesCollection[]DataLabelsCollection[]HasValue = false} // ——// Not so for other chart types where values have more meaning than // percentages // ——else { oChartSpaceCharts[]SeriesCollection[]DataLabelsCollection[]HasPercentage = falseoChartSpaceCharts[]SeriesCollection[]DataLabelsCollection[]HasValue = true}
// ——// Plug your own visual bells and whistles here // ——oChartSpaceCharts[]SeriesCollection[]Caption = StringEmptyoChartSpaceCharts[]SeriesCollection[]DataLabelsCollection[]FontName = verdanaoChartSpaceCharts[]SeriesCollection[]DataLabelsCollection[]FontSize = oChartSpaceCharts[]SeriesCollection[]DataLabelsCollection[]FontBold = trueoChartSpaceCharts[]SeriesCollection[]DataLabelsCollection[]FontColor = redoChartSpaceCharts[]SeriesCollection[]DataLabelsCollection[]Position = ChartDataLabelPositionEnumchLabelPositionCenter
if (chartType == ChartChartTypeEnumchChartTypeBarClustered || chartType == ChartChartTypeEnumchChartTypeBarD || chartType == ChartChartTypeEnumchChartTypeColumnClustered || chartType == ChartChartTypeEnumchChartTypeColumnD)
{ oChartSpaceCharts[]SeriesCollection[]DataLabelsCollection[]Position = ChartDataLabelPositionEnumchLabelPositionOutsideEnd}
oChartSpaceCharts[]SeriesCollection[]SetData (OWCChartDimensionsEnumchDimCategoriesConvertToInt(OWCChartSpecialDataSourcesEnumchDataLiteral) chartCategoriesStr)
oChartSpaceCharts[]SeriesCollection[]SetData (OWCChartDimensionsEnumchDimValuesConvertToInt(OWCChartSpecialDataSourcesEnumchDataLiteral) chartValuesStr)
return oChartSpace}
#region 属性设置public string[] chartCategoriesArrValue { get { return chartCategoriesArr} set { chartCategoriesArr = value}
public string[] chartValuesArrValue { get { return chartValuesArr
} set { chartValuesArr = value} public string chartTypeValue { get { return chartTypeCh} set { chartTypeCh = value} public string chartTitleValue { get { return chartTitle} set { chartTitle = value} #endregion }
//调用 首先需要在页面上放置一个Image来显示产生的统计图
public void ShowChart()
{
//初始化赋值chartFactorychartCategoriesArrValue = chartCategorieschartFactorychartValuesArrValue = chartValueschartFactorychartTitleValue = chartTitlechartFactorychartTypeValue = chartType
OWCChartSpaceClass oChartSpace = chartFactoryBuildCharts()string path = ServerMapPath() + @\images\Chartjpeg //产生图片并保存 页可以是png gif图片oChartSpaceExportPicture(pathjpeg )ImageImageUrl = path // 显示统计图}
// 保存统计图请参照上一篇文章
//由于每次生成的统计图都会覆盖原来的图片所以有必要的话可以用日期加时间的方式来作为图片的名字但是这样将会产生很多图片需及时处理如不需要只需取同名覆盖原来图片即可