原創|使用教程|編輯:郝浩|2013-08-21 14:04:07.000|閱讀 518 次
概述:Chart FX 7是一款輕量級.NET圖表控件,他可應用于Visual Studio、VS.Net、 WPF、 Silverlight、 Java ASP、 Client Server & SQL Reporting 應用程序。 不過在使用Chart FX 7的時候還是會遇到各種問題,今天和大家一起來解決自定義標簽中的一些疑難。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Chart FX 7是一款輕量級.NET圖表控件,他可應用于Visual Studio、VS.Net、 WPF、 Silverlight、 Java ASP、 Client Server & SQL Reporting 應用程序。 不過在使用Chart FX 7的時候還是會遇到各種問題,今天和大家一起來解決自定義標簽中的一些疑難。
系統:Windows 7(64位)
控件版本:Chart FX 7( Chart FX for Visual Studio 2005 )
為了將數據填進條形圖,使用了以下代碼:
string mySelectQuery = "SELECT * from SampleFinancial"; string myConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=Samples.mdb;"; System.Data.OleDb.OleDbConnection myConnection = new System.Data.OleDb.OleDbConnection(myConnectionString); System.Data.DataSet ds = new System.Data.DataSet(); System.Data.OleDb.OleDbDataAdapter adapter = new System.Data.OleDb.OleDbDataAdapter(mySelectQuery, myConnection); adapter.Fill(ds, "Financial"); chart1.DataSourceSettings.Fields.Add(new FieldMap("Date",FieldUsage.XValue)); chart1.DataSourceSettings.Fields.Add(new FieldMap("Closed",FieldUsage.Value)); chart1.DataSource = ds.Tables[0]; I want to set a custom label to every point. For example, I want to set the word "Hello" to every point in the chart. I am trying to do this by using the following code (I should do that for every point in my chart): chart1.Series[0].PointLabels.Visible = true; chart1.Series[0].PointLabels.Format = "%L"; chart1.Points[0, 1].Text = "Hello";
然后,我希望在每一個點上都設置自定義標簽。例如:我想要將"Hello"這個詞添加進圖表的每一個點。
使用以下代碼完成這項工作:
chart1.Series[0].PointLabels.Format = "%L"; chart1.Points[0, 1].Text = "Hello";
實際上,我要做的是在圖表中每一個點都得到這樣的效果,上面的代碼還不能達到我期望的效果。所以我們需要尋找途徑對其進行修改。
參考Chart FX 7中附帶的氣泡圖示例:
--在區域中設置FieldUsage,將文本保存為標簽
--讀取所有的標簽,設置在一個數組的字符串
--使用chart1_GetPointLabel從這個字符串中讀取點的文本屬性
按照前面敘述的方式,chart1_GetPointLabel可能不能正常工作,此時我們在Proyects
Samples>BordersandBackgrounds>InitializeComponent中添加以下代碼:
chart1.AllSeries.PointLabels.Visible = true; chart1.GetPointLabel += new ChartFX.WinForms.PointLabelEventHandler (chart1_GetPointLabel);
如果事件被觸發,問題解決,如果沒有,請看看下文。
代碼:chart1_GetPointLabel
例如: Proyects Samples中的proyect Panes,事件無法在其他pane中觸發,只能在主pane中工作。
因為不同pane意味著不同的軸,所以可以設置軸的"notify"屬性為"true"。
代碼:chart1.AxesY[index].Notify = true;
按照下面的代碼設置,事件依舊在一個系列中觸發:
ChartFX.WinForms.Pane pane1 = new ChartFX.WinForms.Pane(); chart1.Panes.Add(pane1); AxisY axisy = new AxisY(); chart1.AxesY.Add(axisy); chart1.Series[1].AxisY = axisy; chart1.Series[0].Pane = chart1.Panes[0]; chart1.Series[1].Pane = chart1.Panes[1]; chart1.AllSeries.PointLabels.Visible = true; chart1.GetPointLabel += new PointLabelEventHandler(chart1_GetPointLabel); for (int i = 0; i < chart1.AxesY.Count; i++) { chart1.AxesY[i].Notify = true; } And the event: int cant = 0; void chart1_GetPointLabel(object sender, PointLabelEventArgs e) { e.Text = "serie: " + e.Series + " " + cant; cant++; }
根據我們上文講到的內容,我們可以添加pane到集合,與之關聯的軸也可能將隨之添加進軸集合,我們可以設置以下代碼:
pane1.AxisY.Notify = true;
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網