using Microsoft.Office.Interop.Owc11; 导入命名空间
//使用Microsoft.Office.Interop.Owc11进行绘图
protected void GetDistrictSales(string getDate)
{
DataSet ds = admin.GetDistrictReg(getDate);
GridView1.DataSource = ds.Tables["GetDistrictReg"];
GridView1.DataBind();
//DataList1.DataSource = ds.Tables["GetDistrictReg"];
//DataList1.DataBind();
string x = "";
string y = "";
//string file;
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
x = ds.Tables["GetDistrictReg"].Rows[0]["d_districtName"].ToString();
y = ds.Tables["GetDistrictReg"].Rows[0]["coun"].ToString();
for (int i = 1; i < ds.Tables[0].Rows.Count; i++)
{
x += '/t' + ds.Tables[0].Rows[i]["d_districtName"].ToString();
y += '/t' + ds.Tables[0].Rows[i]["coun"].ToString();
}
//创建ChartSpace对象来放置图表
ChartSpace objCSpace = new ChartSpaceClass();
//在ChartSpace对象中添加图表,Add方法返回chart对象
ChChart objChart = objCSpace.Charts.Add(0);
//指定图表的类型。类型由ChartChartTypeEnum枚举值得到
objChart.Type = ChartChartTypeEnum.chChartTypeColumnClustered;
//设置两柱之间的间距,数值越大柱子越细
objChart.GapWidth = 500;
//指定图表是否需要图例
objChart.HasLegend = true;
//给定标题
objChart.HasTitle = true;
objChart.Title.Caption = getDate + "各地区报名人数汇总";
//给定x,y轴的图示说明
//x轴
objChart.Axes[0].HasTitle = true;
objChart.Axes[0].Title.Caption = "X : 区域: ";//+ danwei;
objChart.Axes[0].Title.Font.Size = 12;
objChart.Axes[0].Title.Font.Color = "blue";
objChart.Axes[0].Font.Size = 10;
objChart.Axes[0].Font.Bold = true;
//y轴
objChart.Axes[1].HasTitle = true;
objChart.Axes[1].Title.Caption = "Y : ";
objChart.Axes[1].Title.Font.Color = "blue";
objChart.Axes[1].Title.Font.Size = 12;
objChart.Axes[1].Font.Size = 10;
objChart.Axes[1].Font.Bold = true;
// objChart.SeriesCollection[1].DataLabelsCollection[0].HasValue = true;
//objChart.SeriesCollection[1].DataLabelsCollection.Add();
//计算数据
/*categories 和 values 可以用tab分割的字符串来表示*/
//string strSeriesName = "图例 1";
//添加一个series
objChart.SeriesCollection.Add(0);
//给定series的名字
//objChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimSeriesNames, +(int)ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName);
//给定分类
objChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, +(int)ChartSpecialDataSourcesEnum.chDataLiteral, x);
//给定值
objChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, y);
//给每个柱子上绑定数据
objChart.SeriesCollection[0].DataLabelsCollection.Add();
//是否绑定名称
objChart.SeriesCollection[0].DataLabelsCollection[0].HasCategoryName = false;
//设置柱子的字体大小以及颜色
objChart.SeriesCollection[0].DataLabelsCollection[0].Font.Size = 10;
objChart.SeriesCollection[0].DataLabelsCollection[0].Font.Bold = true;
//输出成GIF文件.
//file = "/" + Guid.NewGuid().ToString() + ".gif";
string strAbsolutePath = (Server.MapPath(".")) + "//ShowData1.gif";
//file = Guid.NewGuid().ToString() + ".gif";
//string strAbsolutePath = (Server.MapPath(".")) + "//" + file;
objCSpace.ExportPicture(strAbsolutePath, "GIF", 780, 350);
Image1.Visible = true;
}
else
{
//file = "/images/0.gif";
Image1.Visible = false;
}
}
使用Microsoft.Office.Interop.Owc11进行绘图
最新推荐文章于 2019-12-18 13:10:17 发布