頁面代碼:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="_ReportOwc.aspx.cs" Inherits="_ReportOwc" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>無標題頁</title>
<link href="../images/xj_style.css" _fcksavedurl=""../images/xj_style.css"" _fcksavedurl=""../images/xj_style.css"" rel="stylesheet" type="text/css" />
<script language="javascript" src="../System_Web_Resources.js" type="text/css"></script>
</head>
<body οnlοad="parent.window.document.all.myiframe.style.height=document.body.scrollHeight+10;">
<form id="form1" runat="server">
<table style="width: 100%" id="TABLE2" runat="server">
<tr>
<td align="center" colspan="1" rowspan="1" style="height: 23px; width: 949px;" valign="top">
<table id="Table4" border="0" cellpadding="0" cellspacing="0" width="98%">
<tr>
<td align="left" style="height: 43px" valign="bottom" width="40%">
<table id="Table5" border="0" cellpadding="0" cellspacing="0" style="border-bottom: #ffffff 1px solid">
<tr>
<td class="lmstyle">
<img align="Middle" height="20" src="../images/blacksjbiao_big.gif" width="15" />
<asp:Label ID="LabelMailTitle" runat="server" Font-Size="14px" Text="統計圖表"></asp:Label></td>
<td align="left">
<img height="27" src="../images/lmtu_right.gif" width="27" /></td>
</tr>
</table>
</td>
<td style="height: 43px" width="60%">
<div align="right">
<img height="41" src="../images/index2.gif" width="306" /></div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="left" rowspan="2" valign="top" style="width: 949px">
<table id="Table1" border="0" cellpadding="1" cellspacing="1" width="100%">
<tr>
<td style="height: 24px">
選擇時間段:<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList3" runat="server">
</asp:DropDownList>—
<asp:DropDownList ID="DropDownList4" runat="server">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList5" runat="server">
</asp:DropDownList>
<asp:Button ID="btnSelect" runat="server" OnClick="btnSelect_Click" Text="檢索" CssClass="xjbutton1" />
選擇圖表類型:
<asp:DropDownList ID="_DropDownListtype" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList_SelectedIndexChanged">
</asp:DropDownList>
<asp:Button ID="Button3" runat="server" Text="繪製餅圖" OnClick="Button3_Click" Visible="False" CssClass="xjbutton1" />
<asp:Button ID="Button2" runat="server" Text="繪製條狀圖" OnClick="Button2_Click" Visible="False" CssClass="xjbutton1" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="繪製柱狀圖" Visible="False" CssClass="xjbutton1" /></td>
</tr>
</table>
</td>
</tr>
<tr>
</tr>
<tr>
<td align="center" valign="top" style="width: 949px; height: 32px">
<asp:Image ID="Image1" runat="server" /></td>
</tr>
</table>
<font face="宋體">
<asp:TreeView ID="TreeView1" runat="server" Visible="False">
<Nodes>
<asp:TreeNode Text="簡單檢索" Value="0"></asp:TreeNode>
</Nodes>
</asp:TreeView>
</font>
</form>
</body>
</html>
C#代碼:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.Office.Interop.Owc11;
using System.Text;
public partial class _ReportOwc : System.Web.UI.Page
{
MyCRM.DB db = new MyCRM.DB();
ChartFactory chartFactory=new ChartFactory();
DataTable dt=new DataTable();
DataTable treetable = new DataTable();
OWCChart11 chart = new OWCChart11();
string filepath ="";
public static Hashtable chartMap = new Hashtable();
string type = "dept";
string sql = "select d.name,count(d.name) from person p join dept d on d.id=p.dept where person_state='正常' group by d.name";
public void Page_Load(object sender, System.EventArgs e)
{
dt = db.ececSelectSql("select top 50 person.truename,wage.薪資 from person left join wage on person.id=wage.員工姓名");
filepath= Server.MapPath(".") + "//ChartImages";
Image1.ImageUrl="";
InitTypeMap();
treetable = db.ececSelectSql("select col_name,show_name from tablestruct where table_name='person' order by [id]");
// 在此處放置用戶代碼以初始化頁面
#region 按鈕繪製圖形
chart.Title = "標題";
chart.SeriesName = "圖例";
chart.PhaysicalImagePath = filepath;
chart.PicHight = 320;
chart.PicWidth = 500;
chart.DataSource = dt;//這是你的數據源
#endregion
if (!IsPostBack)
{
deleteFile();
//默認繪製
for (int i = 1; i < 13; i++)
{
ListItem item = new ListItem();
item.Text = Convert.ToString(DateTime.Now.Year-i)+"年";
item.Value = Convert.ToString(DateTime.Now.Year-i);
DropDownList2.Items.Add(item);
DropDownList4.Items.Add(item);
item = new ListItem();
item.Text = Convert.ToString(i) + "月";
item.Value = Convert.ToString(i);
DropDownList3.Items.Add(item);
DropDownList5.Items.Add(item);
}
}
if (Request.QueryString["type"] != null)
{
type = Request.QueryString["type"].ToString().Trim();
//Response.Write(type);
}
else
{
type = "dept";
}
switch (type)
{
case "post"://職務
sql = "select d.post,count(d.post) from person p join post d on d.id=p.post where person_state='正常' group by d.post";
break;
case "dept"://部門
sql = "select d.name,count(d.name) from person p join dept d on d.id=p.dept where person_state='正常' group by d.name";
break;
case "sex"://性別
sql = "select sex,count(sex) from person where person_state='正常' group by sex";
break;
case "PoliticsVisage"://政治面貌
sql = "select PoliticsVisage,count(PoliticsVisage) from person where person_state='正常' group by PoliticsVisage";
break;
case "person_state"://員工狀態
sql = "select [person_state],count([person_state]) from person group by [person_state]";
break;
default:
break;
}
DropDownList_SelectedIndexChanged(sender, e);
}
public void deleteFile()
{
string[] strFileName=System.IO.Directory.GetFiles(Server.MapPath(".")+@"/ChartImages/");
for(int i=0;i<strFileName.Length;i++)
{
System.IO.FileInfo file=new System.IO.FileInfo(strFileName[i]);
string strtemp=file.Name.Split('.')[0];
if (strtemp.Length > 8)
{
strtemp = strtemp.Substring(0, 4) + "-" + strtemp.Substring(4, 2) + "-" + strtemp.Substring(6, 2);
if (Convert.ToDateTime(strtemp) < DateTime.Now.AddDays(-1))
{
if (file.Exists)
{
file.Delete();
}
}
}
}
}
public void InitTypeMap()
{
chartMap.Clear();
string str = "";
if (_DropDownListtype.Items.Count > 0)
{
str = _DropDownListtype.SelectedItem.Text;
}
_DropDownListtype.Items.Clear();
Microsoft.Office.Interop.Owc11.ChartChartTypeEnum[] chartTypes = new Microsoft.Office.Interop.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};
string[] chartTypesCh = new string[] { "垂直柱狀統計圖", "3D垂直柱狀統計圖", "水平柱狀統計圖", "3D水平柱狀統計圖", "區域統計圖", "3D區域統計圖", "中空餅圖", "折線統計圖", "3D折線統計圖", "折線帶點統計圖", "餅圖", "3D餅圖", "網狀統計圖", "弧線統計圖" };
for (int i = 0; i < chartTypes.Length; i++)
{
chartMap.Add(chartTypesCh[i], chartTypes[i]);
}
for (int i = 0; i < chartTypes.Length; i++)
{
ListItem ii = new ListItem(chartTypesCh[i]);
_DropDownListtype.Items.Add(ii);
}
foreach (ListItem ii in _DropDownListtype.Items)
{
if (ii.Text == str)
{
ii.Selected = true;
}
}
}
#region 按鈕事件
public void Button1_Click(object sender, System.EventArgs e)
{
this.Image1.ImageUrl = @"./ChartImages/" + chart.CreateColumn();//顯示給圖像控件。
}
public void Button2_Click(object sender, System.EventArgs e)
{
this.Image1.ImageUrl = @"./ChartImages/" + chart.CreateBar();//顯示給圖像控件。
}
public void Button3_Click(object sender, System.EventArgs e)
{
this.Image1.ImageUrl = @"./ChartImages/" + chart.CreatePie();//顯示給圖像控件。
}
//按鈕繪製類
public class OWCChart11
{
#region 屬性
public string _phaysicalimagepath;
public string _title;
public string _seriesname;
public int _picwidth;
public int _pichight;
public DataTable _datasource;
public string strCategory;
public string strValue;
/// <summary>
/// 圖片存放路徑
/// </summary>
public string PhaysicalImagePath
{
set { _phaysicalimagepath = value; }
get { return _phaysicalimagepath; }
}
/// <summary>
/// 圖片標題
/// </summary>
public string Title
{
set { _title = value; }
get { return _title; }
}
/// <summary>
/// 圖片說明
/// </summary>
public string SeriesName
{
set { _seriesname = value; }
get { return _seriesname; }
}
/// <summary>
/// 圖片寬度
/// </summary>
public int PicWidth
{
set { _picwidth = value; }
get { return _picwidth; }
}
/// <summary>
/// 圖片高度
/// </summary>
public int PicHight
{
set { _pichight = value; }
get { return _pichight; }
}
/// <summary>
/// 圖片數據源
/// </summary>
public DataTable DataSource
{
set
{
_datasource = value;
strCategory = GetColumnsStr(_datasource);
strValue = GetValueStr(_datasource);
}
get { return _datasource; }
}
/// <summary>
/// 列類型
/// </summary>
public string GetColumnsStr(DataTable dt)
{
StringBuilder strList = new StringBuilder();
foreach (DataRow r in dt.Rows)
{
strList.Append(r[0].ToString() + '/t');
}
return strList.ToString();
}
/// <summary>
/// 列值
/// </summary>
public string GetValueStr(DataTable dt)
{
StringBuilder strList = new StringBuilder();
foreach (DataRow r in dt.Rows)
{
strList.Append(r[1].ToString() + '/t');
}
return strList.ToString();
}
#endregion
public OWCChart11()
{
}
public OWCChart11(string PhaysicalImagePath, string Title, string SeriesName)
{
_phaysicalimagepath = PhaysicalImagePath;
_title = Title;
_seriesname = SeriesName;
}
/// <summary>
/// 柱形圖
/// </summary>
/// <returns></returns>
public string CreateColumn()
{
Microsoft.Office.Interop.Owc11.ChartSpace objCSpace = new Microsoft.Office.Interop.Owc11.ChartSpaceClass();//創建ChartSpace對象來放置圖表
Microsoft.Office.Interop.Owc11.ChChart objChart = objCSpace.Charts.Add(0);//在ChartSpace對象中添加圖表,Add方法返回chart對象
//指定圖表的類型。類型由OWC.ChartChartTypeEnum枚舉值得到//Microsoft.Office.Interop.OWC.ChartChartTypeEnum
//objChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnClustered;
objChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnClustered;
//指定圖表是否需要圖例
objChart.HasLegend = true;
//標題
objChart.HasTitle = true;
objChart.Title.Caption = _title;
objChart.Title.Font.Bold = true;
objChart.Title.Font.Color = "blue";
#region 樣式設置
//旋轉
objChart.Rotation = 360;//表示指定三維圖表的旋轉角度
objChart.Inclination = 10;//表示指定三維圖表的視圖斜率。有效範圍爲 -90 到 90
//背景顏色
objChart.PlotArea.Interior.Color = "yellow";
//底座顏色
objChart.PlotArea.Floor.Interior.Color = "green";
objChart.Overlap = 50;//單個類別中標誌之間的重疊量
#endregion
//x,y軸的圖示說明
objChart.Axes[0].HasTitle = true;
objChart.Axes[0].Title.Caption = "X : 類別";
objChart.Axes[1].HasTitle = true;
objChart.Axes[1].Title.Caption = "Y : 數量";
//添加一個series
Microsoft.Office.Interop.Owc11.ChSeries ThisChSeries = objChart.SeriesCollection.Add(0);
//給定series的名字
ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames,
Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), SeriesName);
//給定分類
ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories,
Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strCategory);
//給定值
ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues,
Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strValue);
Microsoft.Office.Interop.Owc11.ChDataLabels dl = objChart.SeriesCollection[0].DataLabelsCollection.Add();
dl.HasValue = true;
// dl.Position=Microsoft.Office.Interop.Owc11.ChartDataLabelPositionEnum.chLabelPositionOutsideEnd;
string filename = DateTime.Now.ToString("yyyyMMddHHmmssff") + ".gif";
string strAbsolutePath = _phaysicalimagepath + "//" + filename;
objCSpace.ExportPicture(strAbsolutePath, "GIF", _picwidth, _pichight);//輸出成GIF文件.
return filename;
}
/// <summary>
/// 餅圖
/// </summary>
/// <returns></returns>
public string CreatePie()
{
Microsoft.Office.Interop.Owc11.ChartSpace objCSpace = new Microsoft.Office.Interop.Owc11.ChartSpaceClass();//創建ChartSpace對象來放置圖表
Microsoft.Office.Interop.Owc11.ChChart objChart = objCSpace.Charts.Add(0);//在ChartSpace對象中添加圖表,Add方法返回chart對象
//指定圖表的類型
objChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypePie;
//指定圖表是否需要圖例
objChart.HasLegend = true;
//標題
objChart.HasTitle = true;
objChart.Title.Caption = _title;
//添加一個series
Microsoft.Office.Interop.Owc11.ChSeries ThisChSeries = objChart.SeriesCollection.Add(0);
//給定series的名字
ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames,
Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), SeriesName);
//給定分類
ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories,
Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strCategory);
//給定值
ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues,
Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strValue);
//表示系列或趨勢線上的單個數據標誌
Microsoft.Office.Interop.Owc11.ChDataLabels dl = objChart.SeriesCollection[0].DataLabelsCollection.Add();
dl.HasValue = true;
dl.HasPercentage = true;
//圖表繪圖區的圖例放置在右側。
// dl.Position=Microsoft.Office.Interop.Owc11.ChartDataLabelPositionEnum.chLabelPositionRight;
string filename = DateTime.Now.ToString("yyyyMMddHHmmssff") + ".gif";
string strAbsolutePath = _phaysicalimagepath + "//" + filename;
objCSpace.ExportPicture(strAbsolutePath, "GIF", _picwidth, _pichight);//輸出成GIF文件.
return filename;
}
/// <summary>
/// 條形圖
/// </summary>
/// <returns></returns>
public string CreateBar()
{
Microsoft.Office.Interop.Owc11.ChartSpace objCSpace = new Microsoft.Office.Interop.Owc11.ChartSpaceClass();//創建ChartSpace對象來放置圖表
Microsoft.Office.Interop.Owc11.ChChart objChart = objCSpace.Charts.Add(0);//在ChartSpace對象中添加圖表,Add方法返回chart對象
//指定圖表的類型。類型由OWC.ChartChartTypeEnum枚舉值得到//Microsoft.Office.Interop.OWC.ChartChartTypeEnum
objChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBarClustered;
//指定圖表是否需要圖例
objChart.HasLegend = true;
//標題
objChart.HasTitle = true;
objChart.Title.Caption = _title;
objChart.Title.Font.Bold = true;
objChart.Title.Font.Color = "blue";
#region 樣式設置
// //旋轉
objChart.Rotation = 360;//表示指定三維圖表的旋轉角度
objChart.Inclination = 10;//表示指定三維圖表的視圖斜率。有效範圍爲 -90 到 90
//背景顏色
objChart.PlotArea.Interior.Color = "red";
//底座顏色
objChart.PlotArea.Floor.Interior.Color = "green";
objChart.Overlap = 50;//單個類別中標誌之間的重疊量
#endregion
//x,y軸的圖示說明
objChart.Axes[0].HasTitle = true;
objChart.Axes[0].Title.Caption = "X : 類別";
objChart.Axes[1].HasTitle = true;
objChart.Axes[1].Title.Caption = "Y : 數量";
//添加一個series
Microsoft.Office.Interop.Owc11.ChSeries ThisChSeries = objChart.SeriesCollection.Add(0);
//給定series的名字
ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames,
Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), SeriesName);
//給定分類
ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories,
Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strCategory);
//給定值
ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues,
Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strValue);
Microsoft.Office.Interop.Owc11.ChDataLabels dl = objChart.SeriesCollection[0].DataLabelsCollection.Add();
dl.HasValue = true;
// dl.Position=Microsoft.Office.Interop.Owc11.ChartDataLabelPositionEnum.chLabelPositionOutsideEnd;
string filename = DateTime.Now.ToString("yyyyMMddHHmmssff") + ".gif";
string strAbsolutePath = _phaysicalimagepath + "//" + filename;
objCSpace.ExportPicture(strAbsolutePath, "GIF", _picwidth, _pichight);//輸出成GIF文件.
return filename;
}
}
#endregion
#region 下拉框事件
public void DropDownList_SelectedIndexChanged(object sender, System.EventArgs e)
{
string[] chartCategories = new string[10];
string[] chartValues = new string[10];
//Response.Write(sql);
DataTable ddt=db.ececSelectSql(sql);
for (int i = 0; i < ddt.Rows.Count; i++)
{
chartCategories[i] = ddt.Rows[i][0].ToString();
chartValues[i] = ddt.Rows[i][1].ToString();
}
chartFactory.chartCategoriesArrValue = chartCategories;
chartFactory.chartValuesArrValue = chartValues;
chartFactory.chartTitleValue = "統計圖表";
chartFactory.chartTypeValue = _DropDownListtype.SelectedItem.Text;
Microsoft.Office.Interop.Owc11.ChartSpaceClass oChartSpace = chartFactory.BuildCharts();
string filename = DateTime.Now.ToString("yyyyMMddHHmmssff") + ".png";
string path = Server.MapPath(".") + @"/ChartImages/" + filename; //產生圖片並保存,還可以是png gif圖片
if (System.IO.File.Exists(path))
{
System.IO.File.Delete(path);
}
oChartSpace.ExportPicture(path, "png", 470,330);
Image1.ImageUrl = @"./ChartImages/" + filename; // 顯示統計圖
}
#region 下拉框繪製類
public class ChartFactory
{
public ChartFactory()
{
}
public System.Web.UI.WebControls.Image imgHondaLineup;
public string[] chartCategoriesArr;
public string[] chartValuesArr;
public Microsoft.Office.Interop.Owc11.ChartChartTypeEnum chartType = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumn3D;//默認值
public static string chartTypeCh = "垂直柱狀圖";
public static string chartTitle = "";
public Microsoft.Office.Interop.Owc11.ChartSpaceClass BuildCharts()
{
string chartCategoriesStr = String.Join("/t", chartCategoriesArr);
string chartValuesStr = String.Join("/t", chartValuesArr);
Microsoft.Office.Interop.Owc11.ChartSpaceClass oChartSpace = new Microsoft.Office.Interop.Owc11.ChartSpaceClass();
int ii = chartMap.Count;
chartType = (ChartChartTypeEnum)chartMap[chartTypeCh];
if (chartType == ChartChartTypeEnum.chChartTypePie ||
chartType == ChartChartTypeEnum.chChartTypePie3D ||
chartType == ChartChartTypeEnum.chChartTypeDoughnut)
{
oChartSpace.HasChartSpaceLegend = true;
oChartSpace.ChartSpaceLegend.Position = ChartLegendPositionEnum.chLegendPositionBottom;
}
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;
oChartSpace.Charts[0].SeriesCollection.Add(0);
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection.Add();
if (chartType == ChartChartTypeEnum.chChartTypePie ||
chartType == ChartChartTypeEnum.chChartTypePie3D ||
chartType == ChartChartTypeEnum.chChartTypeDoughnut)
{
//oChartSpace.Charts[0].HasLegend = true;
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].HasPercentage = true ;
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].HasValue = false;
}
else
{
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].HasPercentage = false;
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].HasValue = true;
}
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 = false;
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(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories,
Convert.ToInt32(Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral), chartCategoriesStr);
oChartSpace.Charts[0].SeriesCollection[0].SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues,
Convert.ToInt32(Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral), chartValuesStr);
return oChartSpace;
}
#region 屬性設置
public string[] chartCategoriesArrValue
{
get
{
return chartCategoriesArr;
}
set
{
chartCategoriesArr = value;
}
}
public string[] chartValuesArrValue
{
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
}
#endregion
#endregion
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
TreeView1.SelectedNodeStyle.BackColor = System.Drawing.Color.PaleGoldenrod;
}
protected void btnSelect_Click(object sender, EventArgs e)
{
DropDownList_SelectedIndexChanged(sender, e);
}
}