1、首先下载owc11 COM组件 [点击下载] 在工程中添加 C:\Program Files\Common Files\Microsoft Shared\Web Components\11 文件下的owc11.dll引用 3、在工程中添加 using OWC11; 4、开始coding 举例如下: private void InitTypeMap() ChartChartTypeEnum.chChartTypeRadarSmoothLine, string[] chartTypesCh = new string [] {“垂直柱状统计图”,”3D垂直柱状统计图”,”水平柱状统计图”,”3D水平柱状统计图”,”区域统计图”,”3D区域统计图”,”中空饼图”,”折线统计图”,”3D折线统计图”,”折线带点统计图”,”饼图”,”3D饼图”,”网状统计图”,”弧线统计图”}; OWC11.ChartSpaceClass oChartSpace = new OWC11.ChartSpaceClass (); // ———————————————————————— chartType = (ChartChartTypeEnum)chartMap[chartTypeCh]; if (chartType == ChartChartTypeEnum.chChartTypePie || oChartSpace.Border.Color = “blue”; oChartSpace.Charts[0].SeriesCollection.Add(0); // ———————————————————————— if (chartType == ChartChartTypeEnum.chChartTypePie || oChartSpace.Charts[0].SeriesCollection[0].SetData (OWC11.ChartDimensionsEnum.chDimValues, return oChartSpace; #region 属性设置 public string[] chartValuesArrValue } //调用 首先需要在页面上放置一个Image来显示产生的统计图 public void ShowChart() //初始化赋值 OWC11.ChartSpaceClass oChartSpace = chartFactory.BuildCharts(); // 保存统计图请参照上一篇文章 //由于每次生成的统计图都会覆盖原来的图片所以有必要的话可以用日期加时间的方式来作为图片的名字,但是这样将会产生很多图片需及时处理,如不需要只需取同名覆盖原来图片即可。
2、注册owc11
public class ChartFactory
{
public ChartFactory()
{
InitTypeMap();
//
// TODO: 在此处添加构造函数逻辑
//
}
protected System.Web.UI.WebControls.Image imgHondaLineup;
private string[] chartCategoriesArr;
private string[] chartValuesArr;
private OWC11.ChartChartTypeEnum chartType = OWC11.ChartChartTypeEnum.chChartTypeColumn3D;//默认值
private static Hashtable chartMap = new Hashtable();
private static string chartTypeCh = “垂直柱状图” ;
private static string chartTitle = “”;
{
chartMap.Clear();
OWC11.ChartChartTypeEnum[] chartTypes = new OWC11.ChartChartTypeEnum[]{ ChartChartTypeEnum.chChartTypeColumnClustered,
ChartChartTypeEnum.chChartTypeColumn3D,
ChartChartTypeEnum.chChartTypeBarClustered,
ChartChartTypeEnum.chChartTypeBar3D,
ChartChartTypeEnum.chChartTypeArea,
ChartChartTypeEnum.chChartTypeArea3D,
ChartChartTypeEnum.chChartTypeDoughnut,
ChartChartTypeEnum.chChartTypeLineStacked,
ChartChartTypeEnum.chChartTypeLine3D,
ChartChartTypeEnum.chChartTypeLineMarkers,
ChartChartTypeEnum.chChartTypePie,
ChartChartTypeEnum.chChartTypePie3D,
ChartChartTypeEnum.chChartTypeSmoothLine};
for(int i=0;i<chartTypes.Length;i++)
{
chartMap.Add(chartTypesCh[i],chartTypes[i]);
}
}
public ChartSpaceClass BuildCharts ()
{
string chartCategoriesStr = String.Join (“\t”, chartCategoriesArr);
string chartValuesStr = String.Join (“\t”, chartValuesArr);
// 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.chChartTypePie3D ||
chartType == ChartChartTypeEnum.chChartTypeDoughnut)
{
oChartSpace.HasChartSpaceLegend = true;
oChartSpace.ChartSpaceLegend.Position = ChartLegendPositionEnum.chLegendPositionBottom;
}
oChartSpace.Charts.Add(0);
oChartSpace.Charts[0].HasTitle = true;
oChartSpace.Charts[0].Type = chartType;
oChartSpace.Charts[0].ChartDepth = 125;
oChartSpace.Charts[0].AspectRatio = 80;
oChartSpace.Charts[0].Title.Caption = chartTitle;
oChartSpace.Charts[0].Title.Font.Bold = true;
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection.Add ();
// If youre charting a pie or a variation thereof percentages make a lot
// more sense than values…
// ————————————————————————
chartType == ChartChartTypeEnum.chChartTypePie3D ||
chartType == ChartChartTypeEnum.chChartTypeDoughnut)
{
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].HasPercentage = true;
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].HasValue = false;
}
// ————————————————————————
// Not so for other chart types where values have more meaning than
// percentages.
// ————————————————————————
else
{
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].HasPercentage = false;
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].HasValue = true;
}
// ————————————————————————
// Plug your own visual bells and whistles here
// ————————————————————————
oChartSpace.Charts[0].SeriesCollection[0].Caption = String.Empty;
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].Font.Name = “verdana”;
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].Font.Size = 10;
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].Font.Bold = true;
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].Font.Color = “red”;
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].Position = ChartDataLabelPositionEnum.chLabelPositionCenter;
if (chartType == ChartChartTypeEnum.chChartTypeBarClustered ||
chartType == ChartChartTypeEnum.chChartTypeBar3D ||
chartType == ChartChartTypeEnum.chChartTypeColumnClustered ||
chartType == ChartChartTypeEnum.chChartTypeColumn3D)
{
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].Position = ChartDataLabelPositionEnum.chLabelPositionOutsideEnd;
}
oChartSpace.Charts[0].SeriesCollection[0].SetData (OWC11.ChartDimensionsEnum.chDimCategories,
Convert.ToInt32(OWC11.ChartSpecialDataSourcesEnum.chDataLiteral), chartCategoriesStr);
Convert.ToInt32(OWC11.ChartSpecialDataSourcesEnum.chDataLiteral), chartValuesStr);
}
public string[] chartCategoriesArrValue
{
get
{
return chartCategoriesArr;
}
set
{
chartCategoriesArr = value;
}
}
{
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
}
{
chartFactory.chartCategoriesArrValue = chartCategories;
chartFactory.chartValuesArrValue = chartValues;
chartFactory.chartTitleValue = chartTitle;
chartFactory.chartTypeValue = chartType;
string path = Server.MapPath(“.”) + @”\images\Chart.jpeg”; //产生图片并保存 页可以是png gif图片
oChartSpace.ExportPicture(path,”jpeg”, 745, 500);
Image1.ImageUrl = path; // 显示统计图
}
asp.net中调用office来制作3d统计图_asp.net实例
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » asp.net中调用office来制作3d统计图_asp.net实例
相关推荐
-      对.net framework 反射的反思_asp.net技巧
-      .net3.5和vs2008中的asp.net ajax_asp.net技巧
-      使用asp.net ajax框架扩展html map控件_asp.net技巧
-      asp.net应用程序资源访问安全模型_asp.net技巧
-      photoshop初学者轻松绘制螺旋漩涡特效_photoshop教程
-      photoshop通道结合图层模式抠狗尾巴草_photoshop教程
-      web.config详解+asp.net优化_asp.net技巧
-      asp.net中多彩下拉框的实现_asp.net技巧