1.Configuring the Chart
圖表配置
當添加控制項後,接著就利用內建的嚮導自訂外表.右擊chart選擇"Chart Wizard".你可以選擇你受需要的圖
表類型.
你可以通過屬性設定圖表的BackColor和ChartStyle
圖表嚮導和視窗屬性非常強大,可以在不需要寫代碼的情況下設定各種圖表的屬性.你可以使用圖表嚮導組裝
圖表資料,但是很少適用於實際的情況(量級數和點的個數等)
當報表配置好後,你可以儲存為一個檔案.這樣的話你可以在其他圖表中重用. 右擊圖表選擇 “Save Chart”
.你可以右擊選擇“Load Chart”進行重用.你可以預先定義圖表模板.你也可以使用LoadChartFromFile方法動態載入.
2.Adding User Interaction With ImageAreas
添加使用者映像地區互動
C1WebChart and C1WebChart3D允許你關聯工具提示和連通圖元素,所以圖表響應滑鼠事件.這些是利用用戶端處理HTML圖片映象
圖片映象在ImageAreas屬性中定義,它是一個結合了tooltips and HRefs圖表項目的集合.tooltips用來屬性懸停在圖表上顯示的提示,HRefs用來設定點擊圖表項目時的觸發的事件
編輯表單內容的ImageAreas集合.點擊按鈕彈出設定介面
例如:當你選擇“ChartData”並設定Tooltip屬性為“{#YVAL:c}”.
3.Adding Data to the Chart
添加資料到圖表
最後的步驟添加資料到你所要顯示的圖表,這一步你需要撰寫代碼
在絕大多數的應用程式中,資料時來之ADO.NET的DataSet,通常結合轉換:過濾,排序,總結.也有可能資料所來自其他的資料來源,例如數組和自訂資料結構.不管資料是來自那裡,你都可以使用ChartDataSeries類中的方法添加資料
例如,從DataTable綁定資料到圖表
private void Page_Load(object sender, EventArgs e)
{
// get dataset (from db or cache)
DataSet ds = GetDataSet();
// filter the data
DataView dv = new DataView(ds.Tables["Sales"]);
dv.RowFilter = "ProductSales >= 40000";
dv.Sort = "ProductSales";
// create an array of data points
PointF[] data = new PointF[dv.Count]
for (int i = 0; i < data.Length; i++)
{
float y = float.Parse(dv[i]["ProductSales"].ToString());
data[i] = new PointF(i, y);
}
// populate chart data points
ChartDataSeries series = _c1webChart.ChartGroups[0].ChartData.SeriesList[0];
series.PointData.CopyDataIn(data);
}