最近做项目,要求生产面积图、柱状图和线性趋势图叠加。也就是组合图形。搜遍百度,没有找到解决方案,后来自己琢磨,终于醍醐灌顶:)
现在,可以实现面积-柱状图、柱状-线图、面积-线图、多条曲线、多面积图、多柱图等等各种变态而实用的图形。要多少组数据就添加多少个OWC11.ChSeries 对象,通过设置Type来设置图形形状:)
具体实现:
一、安装office2003 ,添加如下地址中的OWC11.dll的com引用:
C:\Program Files\Common Files\Microsoft Shared\Web Components\11
二、页面中添加命名空间 using OWC11;
三、拷贝如下不完全代码到页面(请自行添加适当缺少代码,实在不行就给我发邮件吧:),调试生成,ok……
四、确保asp.net对生成的图片保存路径下的目录有写权限,否则 owcChartSpace.ExportPicture(MapPath("./")+"1233.gif","gif", 500, 300); 这行会报错的!
///
/// 作者:xiaok
///
private void Page_Load(object sender, System.EventArgs e)
{
OWC11.ChartSpace owcChartSpace = new OWC11.ChartSpaceClass();
OWC11.ChChart owcChart = owcChartSpace.Charts.Add(0);
string aa = "a \t b \t c \t d";
string bb = "300 \t 15 \t 19 \t 9";
string cc = "44 \t 34 \t 63 \t 334";
string dd = "64 \t 244 \t 263 \t 24";
//首先确定曲线类型为平滑曲线
owcChart.Type = OWC11.ChartChartTypeEnum.chChartTypeSmoothLine;
//设置x轴标尺名称
owcChart.SetData(OWC11.ChartDimensionsEnum.chDimCategories,(int)ChartSpecialDataSourcesEnum.chDataLiteral,aa);
OWC11.ChSeries serUnitSales = owcChart.SeriesCollection.Add(0);
serUnitSales.SetData(OWC11.ChartDimensionsEnum.chDimValues,(int)ChartSpecialDataSourcesEnum.chDataLiteral,bb) ;
OWC11.ChSeries serDispInc = owcChart.SeriesCollection.Add(1);
serDispInc.SetData(OWC11.ChartDimensionsEnum.chDimValues,(int)ChartSpecialDataSourcesEnum.chDataLiteral,cc) ;
OWC11.ChSeries serDispInc2 = owcChart.SeriesCollection.Add(2);
serDispInc2.SetData(OWC11.ChartDimensionsEnum.chDimValues,(int)ChartSpecialDataSourcesEnum.chDataLiteral,dd) ;
OWC11.ChScaling axIncomeAxis = serDispInc.get_Scalings(OWC11.ChartDimensionsEnum.chDimValues);
owcChart.Axes.Add(axIncomeAxis);
//此处设置图形类型
serDispInc.Type = OWC11.ChartChartTypeEnum.chChartTypeColumnClustered;
serDispInc2.Type = OWC11.ChartChartTypeEnum.chChartTypeArea ;
//以GIF格式输出图表,大小为500*300,
owcChartSpace.ExportPicture(MapPath("./")+"1233.gif","gif", 500, 300);
//将Image控件/SPAN>的URL指向该图表文件
imgChart.ImageUrl="1233.gif";
}
ChartChartTypeEnum 枚举类型包括
////////////////////////////////////////////////
chChartTypeArea
chChartTypeArea3D
chChartTypeAreaOverlapped3D
chChartTypeAreaStacked
chChartTypeAreaStacked100
chChartTypeAreaStacked1003D
chChartTypeAreaStacked3D
chChartTypeBar3D
chChartTypeBarClustered
chChartTypeBarClustered3D
chChartTypeBarStacked
chChartTypeBarStacked100
chChartTypeBarStacked1003D
chChartTypeBarStacked3D
chChartTypeBubble
chChartTypeBubbleLine
chChartTypeColumn3D
chChartTypeColumnClustered
chChartTypeColumnClustered3D
chChartTypeColumnStacked
chChartTypeColumnStacked100
chChartTypeColumnStacked1003D
chChartTypeColumnStacked3D
chChartTypeCombo
chChartTypeCombo3D
chChartTypeDoughnut
chChartTypeDoughnutExploded
chChartTypeLine
chChartTypeLine3D
chChartTypeLineMarkers
chChartTypeLineOverlapped3D
chChartTypeLineStacked
chChartTypeLineStacked100
chChartTypeLineStacked1003D
chChartTypeLineStacked100Markers
chChartTypeLineStacked3D
chChartTypeLineStackedMarkers
chChartTypePie
chChartTypePie3D
chChartTypePieExploded
chChartTypePieExploded3D
chChartTypePieStacked
chChartTypePolarLine
chChartTypePolarLineMarkers
chChartTypePolarMarkers
chChartTypePolarSmoothLine
chChartTypePolarSmoothLineMarkers
chChartTypeRadarLine
chChartTypeRadarLineFilled
chChartTypeRadarLineMarkers
chChartTypeRadarSmoothLine
chChartTypeRadarSmoothLineMarkers
chChartTypeScatterLine
chChartTypeScatterLineFilled
chChartTypeScatterLineMarkers
chChartTypeScatterMarkers
chChartTypeScatterSmoothLine
chChartTypeScatterSmoothLineMarkers
chChartTypeSmoothLine
chChartTypeSmoothLineMarkers
chChartTypeSmoothLineStacked
chChartTypeSmoothLineStacked100
chChartTypeSmoothLineStacked100Markers
chChartTypeSmoothLineStackedMarkers
chChartTypeStockHLC
chChartTypeStockOHLC
//////////////////////////////////////////////////
其他详细使用说明请查看Office自带帮助文档
C:\Program Files\Common Files\Microsoft Shared\Web Components\11\2052\OWCVBA11.CHM