原創(chuàng)|使用教程|編輯:郝浩|2013-08-20 11:18:45.000|閱讀 786 次
概述:TeeChart for .Net是一款功能全面、性能穩(wěn)定的圖表控件,受深受用戶好評(píng)。在使用TeeChart for .Net的過程中還是會(huì)遇到各種難題。今天為大家解決TeeChart for .Net添加自定義軸的問題,如果遇到自定義軸的標(biāo)簽和標(biāo)題都超出圖表區(qū)域,比如出現(xiàn)在圖表標(biāo)題上面。應(yīng)該如何解決呢?
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
TeeChart for .Net是一款功能全面、性能穩(wěn)定的圖表控件,受深受用戶好評(píng)。在使用TeeChart for .Net的過程中還是會(huì)遇到各種難題。今天為大家解決TeeChart for .Net添加自定義軸的問題,如果遇到自定義軸的標(biāo)簽和標(biāo)題都超出圖表區(qū)域,比如出現(xiàn)在圖表標(biāo)題上面。應(yīng)該如何解決呢?
大多數(shù)情況下,我們并不知道問題出在什么地方。如遇到這種情況,就只有一步一步操作,找出問題,最后再解決問題。
系統(tǒng):Windows 7(64位)
控件版本:TeeChart for .Net v2013.4
結(jié)果:只能在圖表標(biāo)題上方添加一定空間,坐標(biāo)軸標(biāo)簽依舊在圖表上方,問題沒有解決。
代碼:
Axis customAxis; private void InitializeChart() { tChart1.Aspect.View3D = false; colorGrid1 = new ColorGrid(tChart1.Chart); colorGrid1.FillSampleValues(); customAxis = new Axis(tChart1.Chart); tChart1.Axes.Custom.Add(customAxis); customAxis.Horizontal = true; colorGrid1.HorizAxis = HorizontalAxis.Both; colorGrid1.CustomHorizAxis = customAxis; tChart1.Draw(); customAxis.OtherSide = true; tChart1.Panel.MarginUnits = PanelMarginUnits.Pixels; tChart1.Panel.MarginTop = 50; tChart1.Header.CustomPosition = true; tChart1.Header.Left = tChart1.Width / 2; tChart1.Header.Top = 0; button1.Click +=button1_Click; }
結(jié)果:經(jīng)過這樣操作后,單個(gè)軸標(biāo)簽在圖表區(qū)域顯示。
colorGrid1.HorizAxis = HorizontalAxis.Both; colorGrid1.CustomHorizAxis = customAxis;
結(jié)果:圖表制作順利進(jìn)行,但是按鈕上的標(biāo)簽消失。
只添加:colorGrid1.HorizAxis = HorizontalAxis.Both;
呼出customAxis.labels.Clear()工具,再添加另外的標(biāo)簽,新標(biāo)簽中仍然有許多軸標(biāo)簽在頂部。
添加以下代碼:
private void InitializeChart() { tChart1.Aspect.View3D = false; colorGrid1 = new ColorGrid(tChart1.Chart); colorGrid1.FillSampleValues(); colorGrid1.HorizAxis = HorizontalAxis.Both; AddCustomLabels(tChart1.Axes.Top); tChart1.Draw(); tChart1.Panel.MarginUnits = PanelMarginUnits.Pixels; tChart1.Panel.MarginTop = 50; tChart1.Header.CustomPosition = true; tChart1.Header.Left = tChart1.Width / 2; tChart1.Header.Top = 0; button1.Click += button1_Click; } private void AddCustomLabels(Axis a) { a.Labels.Items.Clear(); a.Labels.Items.Add(colorGrid1.XValues[5], "Point 1"); }
用下面的代碼完成操作:
Axis customAxis; Steema.TeeChart.Styles.ColorGrid colorGrid1; Steema.TeeChart.Styles.ColorGrid auxiliarygrid; private void InitializeChart() { tChart1.Aspect.View3D = false; colorGrid1 = new ColorGrid(tChart1.Chart); auxiliarygrid = new ColorGrid(tChart1.Chart); colorGrid1.FillSampleValues(); customAxis = new Axis(tChart1.Chart); tChart1.Axes.Custom.Add(customAxis); customAxis.Horizontal = true; colorGrid1.HorizAxis = HorizontalAxis.Bottom; auxiliarygrid.CustomHorizAxis = customAxis; auxiliarygrid.ShowInLegend = false; AddCustomLabels(customAxis); tChart1.Draw(); customAxis.OtherSide = true; tChart1.Panel.MarginUnits = PanelMarginUnits.Pixels; tChart1.Panel.MarginTop = 50; tChart1.Header.CustomPosition = true; tChart1.Header.Left = tChart1.Width / 2; tChart1.Header.Top = 0; }
總結(jié):在第四個(gè)步驟,可以看出該圖表是一個(gè)系列下多自定義軸圖表,所以在系列中需要分配每一個(gè)軸,由于,前面三個(gè)步驟沒有如此做,導(dǎo)致軸標(biāo)簽無法全部正常顯示在圖表區(qū)域;第五、第六兩個(gè)步驟中,移除頂軸標(biāo)簽,再增加了另外的標(biāo)簽,并對(duì)多軸進(jìn)行了分配,所以軸標(biāo)簽顯示正常。
下載最新版:TeeChart for .Net圖表控件
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)