在網站中添加圉示有利於別人更直觀的了解各種變化情況,做出正確的決策.
在.net中使用圖示可以直接利用office套件的Microsoft.Office.Interop.Owc11類庫,可以直接從網上下載.
所以在要顯示圖示的頁面,首先添加對該類庫的引用.using Microsoft.Office.Interop.Owc11;
在頁面添加之前先要在網站中添加對該類庫的引用.
以下是具體的實現代碼:
/// <summary>
/// 通过投票值,生成图表
/// </summary>
private void CreateChart()
{
try
{
//创建X坐标的值,表示评价指标
string[] Month = new string[6] { "综合", "个人诚信", "心理素质", "工作态度", "团队协作", "工作能力" };
//创建Y坐标的值,表示指标得分
double[] Count = new double[6]{ 80, 60, 70, 80, 90, 100 };
//创建图表空间
ChartSpace mychartSpace = new ChartSpace();
//在图表空间内添加一个图表对象
ChChart mychart = mychartSpace.Charts.Add(0);
//设置图表类型,本例使用柱形
mychart.Type = ChartChartTypeEnum.chChartTypeColumnClustered;
//设置图表的一些属性
//是否需要图例
mychart.HasLegend = true;
//是否需要主题
mychart.HasTitle = true;
//主题内容
mychart.Title.Caption = "投票情况";
//设置x,y坐标
mychart.Axes[0].HasTitle = true;
mychart.Axes[0].Title.Caption = "属性";
mychart.Axes[1].HasTitle = true;
mychart.Axes[1].Title.Caption = "得分(满分100)";
//添加6个图表块
mychart.SeriesCollection.Add(0);
mychart.SeriesCollection.Add(0);
mychart.SeriesCollection.Add(0);
mychart.SeriesCollection.Add(0);
mychart.SeriesCollection.Add(0);
mychart.SeriesCollection.Add(0);
//设置图表块的属性
//标题
mychart.SeriesCollection[0].Caption = "综合";
//X坐标的值属性
mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Month[0]);
//y坐标的值属性
mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Count[0]);
//第二个块
mychart.SeriesCollection[1].Caption = "个人诚信";
//X坐标的值属性
mychart.SeriesCollection[1].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Month[1]);
//y坐标的值属性
mychart.SeriesCollection[1].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Count[1]);
//第三个块
mychart.SeriesCollection[2].Caption = "心理素质";
//X坐标的值属性
mychart.SeriesCollection[2].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Month[2]);
//y坐标的值属性
mychart.SeriesCollection[2].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Count[2]);
mychart.SeriesCollection[3].Caption = "工作态度";
//X坐标的值属性
mychart.SeriesCollection[3].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Month[3]);
//y坐标的值属性
mychart.SeriesCollection[3].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Count[3]);
mychart.SeriesCollection[4].Caption = "团队协作";
//X坐标的值属性
mychart.SeriesCollection[4].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Month[4]);
//y坐标的值属性
mychart.SeriesCollection[4].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Count[4]);
mychart.SeriesCollection[5].Caption = "工作能力";
//X坐标的值属性
mychart.SeriesCollection[5].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Month[5]);
//y坐标的值属性
mychart.SeriesCollection[5].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Count[5]);
//生成图片500, 450
mychartSpace.ExportPicture(Server.MapPath(".") + @""test.jpg", "jpg", 600, 400);
//加载图片
Image2.ImageUrl = Server.MapPath(".") + @""test.jpg";
}
catch
{
}
}