using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Office.Interop.Owc11;
public partial class owc11 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ImgStatistics.ImageUrl = "../" + getOWCstatisticChartSrc();
}
private string getOWCstatisticChartSrc()
{
//string[] month = new string[12];
//string[,] amount = new string[2,12];
//string[] seriesName = new string[2];
//string[] dataReference = new string[2];
//month = new string[12] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" };
//amount = new string[2, 12] {{ "3434", "4545", "123", "3435", "454", "4575", "415", "878", "424", "764", "6767", "152" },
// { "345", "4545", "4646", "335", "4454", "556", "4646", "445", "279", "788", "566", "935" }};
//seriesName = new string[2] { "Target Amount","Actual Amount"};
string[] month = new string[3];
string[,] amount = new string[2, 3];
string[] seriesName = new string[2];
string[] dataReference = new string[2];
month = new string[3] { "1", "2", "3"};
amount = new string[2, 3] {{ "3434", "4545", "123" },
{ "345", "4545", "4646"}};
seriesName = new string[2] { "Target Amount", "Actual Amount" };
//为x轴指定特定字符串
string X = String.Empty;
foreach (string xData in month)
{
X+= xData + "/t";
}
for (int i = 0; i < amount.Rank; i++)
{
for (int j = 0; j <=amount.GetUpperBound(amount.Rank-1); j++)
{
string arr = amount[i,j];
//Response.Write("Amount[" + i + "][" + j + "]=" + arr +"<br/>");
dataReference[i] += arr +"/t";
}
}
//创建ChartSpace对象来放置图表
ChartSpace staticsSpace = new ChartSpaceClass();
//在ChartSpace对象中添加图表
ChChart addChart = staticsSpace.Charts.Add(0);
//指定绘制图表的类型。类型可以通过OWC.ChartChartTypeEnum枚举值得到
//addChart.Type = ChartChartTypeEnum.chChartTypeColumnClustered; //垂直柱状统计图
addChart.Type = ChartChartTypeEnum.chChartTypeColumn3D; //3D垂直柱状统计图
//addChart.Type = ChartChartTypeEnum.chChartTypeBarClustered; //水平柱状统计图
//addChart.Type = ChartChartTypeEnum.chChartTypeBar3D;//3D水平柱状统计图
//addChart.Type = ChartChartTypeEnum.chChartTypeArea; //区域统计图
//addChart.Type = ChartChartTypeEnum.chChartTypeArea3D; //3D区域统计图
//addChart.Type = ChartChartTypeEnum.chChartTypeDoughnut; //中空饼图,不能为x,y轴添加图示说明
//addChart.Type = ChartChartTypeEnum.chChartTypeLineStacked; //折线统计图
//addChart.Type = ChartChartTypeEnum.chChartTypeLine3D; //3D折线统计图
//addChart.Type = ChartChartTypeEnum.chChartTypeLineMarkers; //折线带点统计图
//addChart.Type = ChartChartTypeEnum.chChartTypePie; //饼图
//addChart.Type = ChartChartTypeEnum.chChartTypePie3D; //3D饼图 ,不能为x,y轴添加图示说明
//addChart.Type = ChartChartTypeEnum.chChartTypeRadarSmoothLine; //网状统计图
//addChart.Type = ChartChartTypeEnum.chChartTypeSmoothLine;//弧线统计图
//addChart.Type = ChartChartTypeEnum.chChartTypePieExploded3D;
//addChart.Type = ChartChartTypeEnum.chChartTypePie3D;
//addChart.Type = ChartChartTypeEnum.chChartTypeSmoothLineStacked100Markers;
//圖例格式
addChart.HasLegend = true;
addChart.Legend.Position = ChartLegendPositionEnum.chLegendPositionBottom;
addChart.Legend.Font.Size = 9;
//标题
addChart.HasTitle = true;
addChart.HasAutoChartDepth = true;
addChart.Title.Position = ChartTitlePositionEnum.chTitlePositionTop;//标题位置
//addChart.Interior.Color = "green";//内部颜色
addChart.Inclination = 12;//倾斜度
addChart.HeightRatio = 666;//比率
//addChart.GapWidth = 20;//柱的左右间隔
//addChart.GapDepth = 20;//柱的前后间隔
//addChart.ChartDepth = 160;
//addChart.BubbleScale =0;//气泡尺寸必需在 0 到 300 之间。
//addChart.HoleSize = 100;//该属性对3D垂直柱状统计图表类型无效。
//为图表添加标题
addChart.Title.Caption = "Client Order Received (Actual vs Target Revised)"; //标题名称
addChart.Title.Font.Size = 10;
addChart.Title.Font.Bold = true;
//addChart.GapDepth = 1;
//为x,y轴添加图示说明
addChart.Axes[0].HasTitle = true;
addChart.Axes[0].Title.Caption = ""; //月份
addChart.Axes[0].Font.Size = 10;
addChart.Axes[1].HasTitle = true;
addChart.Axes[1].Scaling.SplitMinimum = 100;
addChart.Axes[1].Title.Caption = "";//数量
//图背景渐变
addChart.PlotArea.Interior.SetTwoColorGradient(ChartGradientStyleEnum.chGradientDiagonalDown, ChartGradientVariantEnum.chGradientVariantEnd, "LightSkyBlue", "yellow");
for (int s = 0; s < seriesName.Length; s++)
{
//添加一个series系列
addChart.SeriesCollection.Add(s);
//给定series系列的名字
addChart.SeriesCollection[s].SetData(ChartDimensionsEnum.chDimSeriesNames, +(int)ChartSpecialDataSourcesEnum.chDataLiteral, seriesName[s]);
//给定分类
addChart.SeriesCollection[s].SetData(ChartDimensionsEnum.chDimCategories, +(int)ChartSpecialDataSourcesEnum.chDataLiteral, X);
//给定值
addChart.SeriesCollection[s].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, dataReference[s]);
// addChart.SeriesCollection[s].Interior.Color = "#66FF66";//柱的颜色
}
//输出文件.
//string absolutePath = (Server.MapPath(".")) + @"//statisticChart/ShowData.gif";
string absolutePath = (Server.MapPath("../")) + @"statisticChart/ShowData.gif";
Response.Write((Server.MapPath("../")) +"<br/>");
Response.Write(absolutePath);
staticsSpace.ExportPicture(absolutePath, "GIF",300,300);
return "statisticChart/ShowData.gif?" + RandomNowMilData().ToString();
}
private int RandomNowMilData()
{
return new Random(DateTime.Now.Millisecond).Next(10000);
}
}