| 网管联盟 | 网管论坛 | 网管u家 | 网管博客 | 网管软件 | 网管求职 | 小游戏 | 网管搜索 | 网管原创 | 网管聚合 | 网管读摘 | 网管焦点 | 世界素材 | 会员投稿 | 会员中心 |
![]() |
| Windows Linux Cisco 网络技术 数据库 黑客攻防 DotNet Java PHP 认证 新闻资讯 服务器 存储资讯 网络设备 网管学堂 技术专题 焦点 网吧频道 |
1、首先下载owc11 COM组件
2、注册owc11
在工程中添加 C:\Program Files\Common Files\Microsoft Shared\Web Components\11 文件下的owc11.dll引用
网管bitscn_com
3、在工程中添加 网管网www.bitscn.com
using OWC11;
4、开始coding 举例如下: 中国网管论坛bbs.bitsCN.com
public class ChartFactory { public ChartFactory() 网管u家u.bitsCN.com
{ 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 = ""; 网管联盟bitsCN@com
private void InitTypeMap()
网管下载dl.bitscn.com
{ 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.chChartTypeRadarSmoothLine,ChartChartTypeEnum.chChartTypeSmoothLine}; 网管bitscn_com
string[] chartTypesCh = new string [] {"垂直柱状统计图","3D垂直柱状统计图","水平柱状统计图","3D水平柱状统计图","区域统计图","3D区域统计图","中空饼图","折线统计图","3D折线统计图","折线带点统计图","饼图","3D饼图","网状统计图","弧线统计图"};
for(int i=0;i<chartTypes.Length;i++)
{ chartMap.Add(chartTypesCh[i],chartTypes[i]);} public ChartSpaceClass BuildCharts () 中国网管联盟bitsCN.com
{ string chartCategoriesStr = String.Join ("\t", chartCategoriesArr);string chartValuesStr = String.Join ("\t", chartValuesArr); 网管网www.bitscn.com
OWC11.ChartSpaceClass oChartSpace = new OWC11.ChartSpaceClass ();
// ——// 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]; 中国网管论坛bbs.bitsCN.com
if (chartType == ChartChartTypeEnum.chChartTypePie || chartType == ChartChartTypeEnum.chChartTypePie3D || chartType == ChartChartTypeEnum.chChartTypeDoughnut) 中国网管论坛bbs.bitsCN.com
{ oChartSpace.HasChartSpaceLegend = true;oChartSpace.ChartSpaceLegend.Position = ChartLegendPositionEnum.chLegendPositionBottom;}
网管下载dl.bitscn.com
oChartSpace.Border.Color = "blue";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; 网管网www.bitscn.com
oChartSpace.Charts[0].SeriesCollection.Add(0);oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection.Add ();
网管联盟bitsCN@com
// ——// If you're charting a pie or a variation thereof percentages make a lot // more sense than values……
网管网www_bitscn_com
// —— 网管下载dl.bitscn.com
if (chartType == ChartChartTypeEnum.chChartTypePie || chartType == ChartChartTypeEnum.chChartTypePie3D || chartType == ChartChartTypeEnum.chChartTypeDoughnut) 网管u家u.bitsCN.com
{ 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;} 中国网管论坛bbs.bitsCN.com
// ——// 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;
网管网www_bitscn_com
if (chartType == ChartChartTypeEnum.chChartTypeBarClustered || chartType == ChartChartTypeEnum.chChartTypeBar3D || chartType == ChartChartTypeEnum.chChartTypeColumnClustered || chartType == ChartChartTypeEnum.chChartTypeColumn3D)
网管联盟bitsCN_com
{ oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].Position = ChartDataLabelPositionEnum.chLabelPositionOutsideEnd;} 中国网管论坛bbs.bitsCN.com
oChartSpace.Charts[0].SeriesCollection[0].SetData (OWC11.ChartDimensionsEnum.chDimCategories,Convert.ToInt32(OWC11.ChartSpecialDataSourcesEnum.chDataLiteral), chartCategoriesStr); 网管网www.bitscn.com
oChartSpace.Charts[0].SeriesCollection[0].SetData (OWC11.ChartDimensionsEnum.chDimValues,Convert.ToInt32(OWC11.ChartSpecialDataSourcesEnum.chDataLiteral), chartValuesStr); 网管论坛bbs_bitsCN_com
return oChartSpace;}
网管联盟bitsCN_com
#region 属性设置public string[] chartCategoriesArrValue { get { return chartCategoriesArr;} set { chartCategoriesArr = value;} 网管网www.bitscn.com
public string[] chartValuesArrValue { get { return chartValuesArr;
网管u家u.bitsCN.com
} set { chartValuesArr = value;} public string chartTypeValue { get { return chartTypeCh;} set { chartTypeCh = value;} public string chartTitleValue { get { return chartTitle;} set { chartTitle = value;} #endregion } 网管联盟bitsCN@com
//调用 首先需要在页面上放置一个Image来显示产生的统计图 中国网管论坛bbs.bitsCN.com
public void ShowChart() 网管bitscn_com
{
//初始化赋值chartFactory.chartCategoriesArrValue = chartCategories;chartFactory.chartValuesArrValue = chartValues;chartFactory.chartTitleValue = chartTitle;chartFactory.chartTypeValue = chartType;
网管u家u.bitscn@com
OWC11.ChartSpaceClass oChartSpace = chartFactory.BuildCharts();string path = Server.MapPath(".") + @"\images\Chart.jpeg"; //产生图片并保存 页可以是png gif图片oChartSpace.ExportPicture(path,"jpeg", 745, 500);Image1.ImageUrl = path; // 显示统计图} 网管联盟bitsCN_com
// 保存统计图请参照上一篇文章
//由于每次生成的统计图都会覆盖原来的图片所以有必要的话可以用日期加时间的方式来作为图片的名字,但是这样将会产生很多图片需及时处理,如不需要只需取同名覆盖原来图片即可。
网管网www_bitscn_com
|
0
|
评论加载中…