翻譯|使用教程|編輯:王香|2018-09-05 11:19:15.000|閱讀 196 次
概述:本文詳細介紹了在TeeChart for Java中的軸控制——附加軸。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
【下載TeeChart for Java最新版本】
上一篇文章講到軸控制——關鍵領域部分,本文將續講軸控制的附加軸部分。
TeeChart提供5個與數據系列相關的軸:Left、Top、Bottom、Right和Depth。將新系列添加到圖表時,您可以定義系列應與哪些軸相關(轉到“Series”選項卡,“General ”頁面),您可以使用Axis Customdraw方法在圖表上的任何位置重復4個前軸中的任何一個(或全部)。請注意,此方法會復制Axis,但不會添加新的自定義軸。
//fill the Series for this example with random data procedure TForm1.BitBtn1Click(Sender: TObject); Var t:integer; begin For t := 0 To 20 do Series1.AddXY(t, Random(100) - Random(70), '', clRed); end; //Put this code in the OnBeforeDrawValues() event: procedure TForm1.Series1BeforeDrawValues(Sender: TObject); var posaxis :Integer; begin With Chart1 do begin If LeftAxis.Maximum > 0 Then begin //When scrolling or on zoom always keep the gridlines enclosed in the Chart rectangle Canvas.ClipRectangle(ChartRect); //Always draw the 2nd vertical Axis at the middle point of the Chart posaxis := (ChartRect.Left) + (ChartRect.Right - ChartRect.Left) div 2; LeftAxis.CustomDraw(posaxis - 10, posaxis - 20, posaxis, True); //Draw the 2nd Horizontal axis at the level of "10" on the vertical axis posaxis := (LeftAxis.CalcYPosValue(10)); BottomAxis.CustomDraw(posaxis + 10, posaxis + 40, posaxis, True); Canvas.UnClipRectangle; end; end; end;
在此示例中,TeeChart將繪制新軸,一個水平,一個垂直位于圖表的中心。當您滾動圖表(用鼠標右鍵拖動)時,新的垂直軸將始終保持在圖表的中心,新的水平軸將垂直滾動上下移動,新軸是默認軸的精確副本。
與PositionPercent和拉伸屬性一起,可以在圖表上的任何位置浮動無限軸,滾動,縮放和軸命中檢測也適用于自定義創建的軸,現在可以通過圖表編輯器在設計時創建附加軸,也可以在運行時通過幾行代碼創建附加軸:
TeeChart為您提供在設計時創建自定義軸的功能,使其能夠以TeeChart的tee文件格式保存。要實現此目的,請打開圖表編輯器并單擊“Axis”選項卡,然后選擇“+”按鈕以添加自定義軸。然后選擇“Position”選項卡,確保突出顯示新的自定義軸。此頁面上的“Horizontal”復選框允許您將新的自定義軸定義為水平軸或將其保留為默認垂直軸。如上所述,此頁面的其余部分和Axis頁面中的其他選項卡可用于更改自定義軸的比例,增量,標題,標簽,刻度,次刻度和位置。要將此新的自定義軸與所需的數據系列相關聯,請選擇“Series”選項卡,然后轉到“General”頁面,其中下拉列表組合框的“Horizontal Axis水平軸”
Line line1 = new Line(); Line line2 = new Line(); tChart2.getAspect().setView3D(false); tChart2.getPanel().getGradient().setVisible(true); tChart2.getHeader().setText("TeeChart Multiple Axes"); tChart2.getSeries(0).add(line1); tChart2.getSeries(1).add(line2); for(int t = 0; t <= 10; ++t) { line1.add(t, (10 + t), Color.Red); if(t > 1) { line2.add(t, t, Color.Green); } } tChart2.getAxes().getLeft().setStartPosition(0); tChart2.getAxes().getLeft().setEndPosition(50); tChart2.getAxes().getLeft().getAxisPen().color = Color.Red; tChart2.getAxes().getLeft().getTitle().getFont().setColor(Color.Red); tChart2.getAxes().getLeft().getTitle().getFont().setBold(true); tChart2.getAxes().getLeft().getTitle().setText("1st Left Axis");
然后,您可以使用StartPosition和EndPosition方法將新軸與圖表的整體關系定位,這些數字表示為圖表矩形的百分比,其中0(零)(在 垂直軸的情況下)為Top。這些屬性可以應用于標準軸,以在圖表中創建完全分區的“SubCharts”。
Axis axis1 = new Axis(false, false, tChart2.getChart()); tChart2.getAxes().getCustom().add(axis1); line2.setCustomVertAxis(axis1); axis1.setStartPosition(50); axis1.setEndPosition(100); axis1.getAxisPen().setColor(Color.Green); axis1.getTitle().getFont().setColor(Color.Green); axis1.getTitle().getFont().setBold(true); axis1.getTitle().setText("Extra Axis"); axis1.setRelativePosition(20); } }
上面的編碼示例將顯示以下圖表:
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn