翻譯|使用教程|編輯:王香|2018-09-05 11:19:15.000|閱讀 196 次
概述:本文詳細(xì)介紹了在TeeChart for Java中的軸控制——附加軸。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
【下載TeeChart for Java最新版本】
上一篇文章講到軸控制——關(guān)鍵領(lǐng)域部分,本文將續(xù)講軸控制的附加軸部分。
TeeChart提供5個(gè)與數(shù)據(jù)系列相關(guān)的軸:Left、Top、Bottom、Right和Depth。將新系列添加到圖表時(shí),您可以定義系列應(yīng)與哪些軸相關(guān)(轉(zhuǎn)到“Series”選項(xiàng)卡,“General ”頁面),您可以使用Axis Customdraw方法在圖表上的任何位置重復(fù)4個(gè)前軸中的任何一個(gè)(或全部)。請注意,此方法會(huì)復(fù)制Axis,但不會(huì)添加新的自定義軸。
//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將繪制新軸,一個(gè)水平,一個(gè)垂直位于圖表的中心。當(dāng)您滾動(dòng)圖表(用鼠標(biāo)右鍵拖動(dòng))時(shí),新的垂直軸將始終保持在圖表的中心,新的水平軸將垂直滾動(dòng)上下移動(dòng),新軸是默認(rèn)軸的精確副本。
與PositionPercent和拉伸屬性一起,可以在圖表上的任何位置浮動(dòng)無限軸,滾動(dòng),縮放和軸命中檢測也適用于自定義創(chuàng)建的軸,現(xiàn)在可以通過圖表編輯器在設(shè)計(jì)時(shí)創(chuàng)建附加軸,也可以在運(yùn)行時(shí)通過幾行代碼創(chuàng)建附加軸:
TeeChart為您提供在設(shè)計(jì)時(shí)創(chuàng)建自定義軸的功能,使其能夠以TeeChart的tee文件格式保存。要實(shí)現(xiàn)此目的,請打開圖表編輯器并單擊“Axis”選項(xiàng)卡,然后選擇“+”按鈕以添加自定義軸。然后選擇“Position”選項(xiàng)卡,確保突出顯示新的自定義軸。此頁面上的“Horizontal”復(fù)選框允許您將新的自定義軸定義為水平軸或?qū)⑵浔A魹槟J(rèn)垂直軸。如上所述,此頁面的其余部分和Axis頁面中的其他選項(xiàng)卡可用于更改自定義軸的比例,增量,標(biāo)題,標(biāo)簽,刻度,次刻度和位置。要將此新的自定義軸與所需的數(shù)據(jù)系列相關(guān)聯(lián),請選擇“Series”選項(xiàng)卡,然后轉(zhuǎn)到“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方法將新軸與圖表的整體關(guān)系定位,這些數(shù)字表示為圖表矩形的百分比,其中0(零)(在 垂直軸的情況下)為Top。這些屬性可以應(yīng)用于標(biāo)準(zhǔn)軸,以在圖表中創(chuàng)建完全分區(qū)的“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); } }
上面的編碼示例將顯示以下圖表:
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn