翻譯|使用教程|編輯:王香|2018-09-21 17:11:47.000|閱讀 360 次
概述:本文詳細介紹了在TeeChart for Java圖表面板上的自定義繪圖。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
【下載TeeChart for Java最新版本】
添加一個繪圖線:
private void Load() { line1.fillSampleValues(20); line1.setVertAxis(VerticalAxis.BOTH); line1.setHorizAxis(HorizontalAxis.BOTH); tChart1.getAspect.setView3D(false); } public void chartEvent(EventArgs e) { if (e instanceof AfterDrawEventArgs) { IGraphics3D g = tChart1.getGraphics3D(); Point s = new Point(tChart1.getAxes().getLeft().getPosition(), tChart1.getAxes().getTop().getPosition()); Point e = new Point(tChart1.getAxes().getRight().getPosition(), tChart1.getAxes().getBottom().getPosition()); g.MoveTo(s); g.LineTo(e,0); } }
在3D圖表上,由于3D正交位移,軸位置偏離圖表區域。我們可以相應地移動線路:示例(在3D圖表的圖表區域中從左上角到右下角對角繪制線條)
private void Load() { line1.fillSampleValues(20); line1.setVertAxis(VerticalAxis.BOTH); line1.setHorizAxis(HorizontalAxis.BOTH); tChart1.getAspect.setChart3DPercent(50); } public void chartEvent(EventArgs e) { if (e instanceof AfterDrawEventArgs) { IGraphics3D g = tChart1.getGraphics3D(); com.steema.teechart.Point3D s = new com.steema.teechart.Point3D(); s.x = tChart1.getAxes().getLeft().getPosition(); s.y = tChart1.getAxes().getTop().getPosition(); s.z = 0; com.steema.teechart.Point3D e = new com.steema.teechart.Point3D(); e.x = tChart1.getAxes().getRight().getPosition(); e.y = tChart1.getAxes().getBottom().getPosition(); e.z = tChart1.getAspect().width3D; g.moveTo(s); g.lineTo(e); } }
上面的線是使用為繪制線之前繪制的最后一個對象定義的筆和筆刷繪制的。那可能是也可能不是你想要的筆。您可以相應地更改筆:
public void chartEvent(EventArgs e) { if (e instanceof AfterDrawEventArgs) { IGraphics3D g = tChart1.getGraphics3D(); Point p5 = new Point(line1.calcXPos(5), line1.calcYPos(5)); Point p15 = new Point(line1.calcXPos(15), line1.calcYPos(15)); g.getPen().setDashCap(DashCap.SQUARE); g.getPen().setEndCap(LineCap.MITER); g.getPen().setStyle(DashStyle.DASHDOTDOT); g.getPen().setTransparency(70); g.getPen().setWidth(3); g.getPen().setColor(Color.blue); g.moveTo(p5); g.lineTo(p15, 0); } }
以與Canvas Lines類似的方式添加2D Canvas Shapes。以下示例在圖表區域的中心添加一個Rectangle:
2D圖表僅支持2D形狀。
public void chartEvent(EventArgs e) { if (e instanceof AfterDrawEventArgs) { IGraphics3D g = tChart1.getGraphics3D(); Dimension d = new Dimension(100,100); Point p = new Point(((int)(g.getXCenter() - (d.getWidth()/2))),((int)(g.getYCenter() - (d.getHeight()/2)))); com.steema.teechart.Rectangle r = new com.steema.teechart.Rectangle(p,d); g.getPen().setColor(Color.cyan); g.getBrush().setColor(Color.blue); g.rectangle(r); } }
在3D圖表上,您也可以在Z平面中移動矩形。請參閱RectangleWithZ方法。此示例將矩形放置在左側墻壁上,但將其移向圖表后部的中間位置。
private void Load() { point3D1.LinePen.Visible = false; point3D1.fillSampleValues(20); point3D1.setVertAxis(VerticalAxis.BOTH); point3D1.setHorizAxis(HorizontalAxis.BOTH); tChart1.getAspect.setChart3DPercent(50); tChart1.getAxes().getDepth().setVisible(true); } public void chartEvent(EventArgs e) { if (e instanceof AfterDrawEventArgs) { IGraphics3D g = tChart1.getGraphics3D(); Dimension d = new Dimension(100, 100); Point l = new Point(((int)tChart1.getAxes().getLeft().getPosition()),((int)(g.getYCenter() - (d.getHeight() / 2)))); com.steema.teechart.Rectangle r = new com.steema.teechart.Rectangle(l,d); g.getPen().setColor(Color.cyan); g.getBrush().setColor(Color.blue); g.rectangle(r, tChart1.getAspect().width3D/2); }
您可以將3D形狀添加到3D圖表中。此示例在Chart矩形的中間繪制一個Cube:
private void Load() { point3D1.getLinePen().setVisible(false); point3D1.fillSampleValues(20); tChart1.getAspect().setChart3DPercent(50); tChart1.getLegend().setVisible(false); tChart1.getAxes().getDepth().setVisible(true); } public void chartEvent(EventArgs e) { if (e instanceof AfterDrawEventArgs) { IGraphics3D g = tChart1.getGraphics3D(); Dimension d = new Dimension(50,50); Point p = new Point(((int)(g.getXCenter() - (d.getWidth()/2))),((int)(g.getYCenter() - (d.getHeight()/2)))); com.steema.teechart.Rectangle r = new com.steema.teechart.Rectangle(p,d); g.cube(r, 0, 20, true); } }
將文本添加到最后一個矩形:
public void chartEvent(EventArgs e) { if (e instanceof AfterDrawEventArgs) { String text = "My Text"; IGraphics3D g = tChart1.getGraphics3D(); Dimension d = new Dimension(150, 50); Point p = new Point(((int)(g.getXCenter() - (d.getWidth()/2))),((int)(g.getYCenter() - (d.getHeight()/2)))); com.steema.teechart.Rectangle r = new com.steema.teechart.Rectangle(p,d); g.getPen().setColor(Color.blue); g.rectangle(r); g.textOut(((int)(g.getXCenter() - (g.textWidth(text)/2))), ((int)(g.getYCenter() - (g.textHeight(text)/2))), text); } }
通過使用帶有z坐標的TextOut重載,可以將文本放置在不同的3D平面中。
private void Load() { point3D1.fillSampleValues(20); point3D1.getLinePen().setVisible(false); tChart1.getAspect().setChart3DPercent(50); } public void chartEvent(EventArgs e) { if (e instanceof AfterDrawEventArgs) { String text = "My Text"; IGraphics3D g = tChart1.getGraphics3D(); g.textOut(g.getXCenter(), g.getYCenter(), tChart1.getAspect().width3D / 2, text); } }
這個例子取一個Series的第3和第10個值,在它們之間繪制一條Line,并告訴我們新Line的第一個和最后一個點的值以及它們之間的差異:
'First add some data to the empty Chart procedure TForm1.BitBtn1Click(Sender: TObject); begin Series1.FillSampleValues(20); end; private void Load() { tChart1.getAspect().setView3D(false); line1.fillSampleValues(20); } public void chartEvent(EventArgs e) { if (e instanceof AfterDrawEventArgs) { IGraphics3D g = tChart1.getGraphics3D(); if(tChart1.getSeriesCount() > 0){ if(tChart1.getSeries(0).getCount() > 10) { Series s = tChart1.getSeries(0); int h = Convert.ToInt32(g.TextHeight("H")); Point p1 = new Point(s.calcXPos(3), s.calcYPos(3)); Point p2 = new Point(s.calcXPos(10), s.calcYPos(10)); g.getPen().setColor(Color.blue); g.getPen().setWidth(2); g.getPen().setStyle(com.steema.teechart.drawing.DashStyle.DASH); g.moveTo(p1); g.lineTo(p2, 0); g.textOut(p1.x, p1.y - h, "Point value: " + s.getYValues(3).toString()); g.textOut(p2.x, p2.y, "Point value: " + s.getYValues(10).toString()); g.textOut(p2.x, p2.y + h, "Change is: " + s.getYValues(3).toString() - s.getYValues(10).toString()); } } }
購買TeeChart for Java正版授權,請點擊“”喲!
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn