翻譯|使用教程|編輯:王香|2018-09-04 11:16:10.000|閱讀 310 次
概述:本文詳細介紹了在TeeChart for Java中的軸控制——關鍵領域。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
【下載TeeChart for Java最新版本】
將Series數據添加到圖表時,會自動設置軸刻度,可以在設計時通過代碼或在運行時使用Axis方法更改默認值。
添加新系列時,圖表編輯器的“Axis”頁面的“Scales”部分將顯示已選中“Visible”和“Automatic”,并且未選中“Inverted”。在編輯器的底部有兩個選項卡,Maximum和Minimum。在此處,您可以設置“ Offset”值,以在取消選中“Auto”時沿選定軸移動圖表。
Automatic選擇最佳軸刻度范圍以適合您的數據,如果關閉“Automatic”,“Scales”部分將激活選項,您可以更改“Axis”值,從頁面左側的“Axis”列表中選擇要配置的軸,將行系列添加到圖表中添加一個命令按鈕,其中包含以下代碼:
tChart1.removeAllSeries(); tChart1.addSeries(new Line()).fillSampleValues(40);
在按鈕中運行代碼將繪制一個包含40個隨機值的Line Series,現在可以配置軸刻度的最大值和最小值。
tChart1.getAxes().getBottom().setAutomatic(false); tChart1.getAxes().getBottom().setMaximum(36); tChart1.getAxes().getBottom().setMinimum(5);
再次運行代碼將顯示值,具體取決于為Axis配置的值,使用鼠標右鍵可以滾動查看剩余值??梢詫xis scale Maximum和Minimum設置為自動單獨,例如:
tChart1.getAxes().getBottom().setAutomaticMaximum(true); tChart1.getAxes().getBottom().setMinimum(5);
可以定制Axis的間隔,從Axis頁面的Scales部分選擇Desired Increment組合框,并添加所需的增量,可以在運行時通過代碼更改它:
tChart1.getAxes().getBottom().setIncrement(20);
如果您的數據是datetime(您可以通過轉到Series,General頁面將數據設置為系列的日期時間,如此圖所示),圖表,軸頁面和比例部分將顯示日期時間范圍,從所需增量組合框中顯示的范圍中進行選擇,添加一些示例數據:
tChart1.getAxes().getBottom().setIncrement(Utils.getDateTimeStep(DateTimeStep.ONEDAY)); tChart1.getAxes().getBottom().getLabels().setDateTimeFormat("dd MMM yyyy"); DateTime d = DateTime.getNow(); d.add(5,1); tChart2.getSeries(0).add(d, 20); d.add(5,1); tChart2.getSeries(0).add(d, 30); d.add(5,1); tChart2.getSeries(0).add(d, 40); d.add(5,1); tChart2.getSeries(0).add(d, 35);
在運行時更改增量:
tChart2.getAxes().getBottom().setIncrement(com.steema.teechart.DateTimeStep.ONEWEEK);
titles在Axis頁面的titles部分中設置,您可以更改Axis及其字體的標題文本,該角度可以從值0,90,180,270度中選擇。
更改軸標簽頻率時,請記住TeeChart將根據LabelsSeparation方法的設置避免標簽重疊。這意味著如果標簽頻率太高而不適合標簽,那么TeeChart將分配“best fit”。更改標簽角度和標簽分離是2個選項,可幫助您安裝所需的標簽。
您可以將所有標準數字和日期格式應用于Axis標簽,“Axis”頁面的“Labels”部分包含“Values format”字段,如果您的數據是datetime,則字段名稱將更改為“Date time format”。在編輯器中拖動幫助“?” 在該字段上的圖標,以獲得完整的選項列表,在運行時使用:
tChart1.getAxes().getBottom().getLabels().setValueFormat("#,##0.00;(#,##0.00)"); //or for Datetime data tChart1.getAxes().getBottom().getLabels().setDateTimeFormat("dddd/mmmm/yyyy");
軸標簽可以顯示為多行文本而不是單行文本,使用TeeLineSeparator全局常量分隔行,該常量默認為回車符ascii字符(#13)。
//Add the Series labels in this way and apply 'Marks' as Axis labelling style tChart1.getSeries(0).add(1234, "New"+com.steema.teechart.Texts.LineSeparator+" cars", Color.Blue ); tChart1.getSeries(0).add(2000, "Old"+com.steema.teechart.Texts.LineSeparator+" bicycles", Color.Green); tChart1.getPanel().setMarginBottom(10);
DateTime標簽的示例:
有3種刻度類型,您可以更改每種刻度類型的長度,寬度和顏色。如果刻度線寬度設置為1(默認值),則可以將樣式更改為多種線型之一(點,短劃線等),如果width大于1,則將忽略樣式。
tChart1.getAxes().getBottom().getTicks().setLength(7); tChart1.getAxes().getBottom().getTicks().setColor(Color.GREEN); tChart1.getAxes().getBottom().setMinorTickCount(10);
軸有一種方法可以修改每個軸的位置,在此示例中,軸移動到圖表總寬度的50%,因此它顯示在圖表中心:
tChart1.getAxes().getLeft().setRelativePosition(50);
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn