原創(chuàng)|使用教程|編輯:郝浩|2013-08-21 14:04:07.000|閱讀 531 次
概述:Chart FX 7是一款輕量級(jí).NET圖表控件,他可應(yīng)用于Visual Studio、VS.Net、 WPF、 Silverlight、 Java ASP、 Client Server & SQL Reporting 應(yīng)用程序。 不過在使用Chart FX 7的時(shí)候還是會(huì)遇到各種問題,今天和大家一起來解決自定義標(biāo)簽中的一些疑難。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Chart FX 7是一款輕量級(jí).NET圖表控件,他可應(yīng)用于Visual Studio、VS.Net、 WPF、 Silverlight、 Java ASP、 Client Server & SQL Reporting 應(yīng)用程序。 不過在使用Chart FX 7的時(shí)候還是會(huì)遇到各種問題,今天和大家一起來解決自定義標(biāo)簽中的一些疑難。
系統(tǒng):Windows 7(64位)
控件版本:Chart FX 7( Chart FX for Visual Studio 2005 )
為了將數(shù)據(jù)填進(jìn)條形圖,使用了以下代碼:
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"; 
	
然后,我希望在每一個(gè)點(diǎn)上都設(shè)置自定義標(biāo)簽。例如:我想要將"Hello"這個(gè)詞添加進(jìn)圖表的每一個(gè)點(diǎn)。
使用以下代碼完成這項(xiàng)工作:
chart1.Series[0].PointLabels.Format = "%L"; chart1.Points[0, 1].Text = "Hello";
實(shí)際上,我要做的是在圖表中每一個(gè)點(diǎn)都得到這樣的效果,上面的代碼還不能達(dá)到我期望的效果。所以我們需要尋找途徑對(duì)其進(jìn)行修改。
參考Chart FX 7中附帶的氣泡圖示例:
--在區(qū)域中設(shè)置FieldUsage,將文本保存為標(biāo)簽
--讀取所有的標(biāo)簽,設(shè)置在一個(gè)數(shù)組的字符串
--使用chart1_GetPointLabel從這個(gè)字符串中讀取點(diǎn)的文本屬性
按照前面敘述的方式,chart1_GetPointLabel可能不能正常工作,此時(shí)我們?cè)赑royects
Samples>BordersandBackgrounds>InitializeComponent中添加以下代碼:
chart1.AllSeries.PointLabels.Visible = true; chart1.GetPointLabel += new ChartFX.WinForms.PointLabelEventHandler (chart1_GetPointLabel);
如果事件被觸發(fā),問題解決,如果沒有,請(qǐng)看看下文。
代碼:chart1_GetPointLabel
例如: Proyects Samples中的proyect Panes,事件無法在其他pane中觸發(fā),只能在主pane中工作。
因?yàn)椴煌琾ane意味著不同的軸,所以可以設(shè)置軸的"notify"屬性為"true"。
代碼:chart1.AxesY[index].Notify = true;
按照下面的代碼設(shè)置,事件依舊在一個(gè)系列中觸發(fā):
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++;
}
根據(jù)我們上文講到的內(nèi)容,我們可以添加pane到集合,與之關(guān)聯(lián)的軸也可能將隨之添加進(jìn)軸集合,我們可以設(shè)置以下代碼:
pane1.AxisY.Notify = true;
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@ke049m.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)