如何在TeeChart Android中添加自定义标签



我想在图表的左纵轴上添加一个自定义标签:

TChart chart = ...
[...]
Candle series = new Candle(chart.getChart());
series.fillSampleValues(50);
chart.addSeries(series);
[...]
Axis leftAxis = chart.getAxes().getLeft();
TextShape label = new TextShape(chart.getChart());
leftAxis.drawAxisLabel(leftAxis.getPosition(), leftAxis.calcPosValue(500), 0, "CLOSE", label);
[...]

我得到一个异常:

Caused by: java.lang.NullPointerException
    at com.steema.teechart.android.Graphics3DAndroid.rectangle(Graphics3DAndroid.java:168)
    at com.steema.teechart.TextShape.internalDrawShape(TextShape.java:345)
    at com.steema.teechart.TextShape.drawRectRotated(TextShape.java:387)
    at com.steema.teechart.axis.Axis.drawAxisLabel(Axis.java:2915)
    at com.steema.teechart.axis.Axis.drawAxisLabel(Axis.java:2649)
    at com.forexite.chart.teechart.TeeChartFragment.addSeries(TeeChartFragment.java:102)
    at com.forexite.chart.teechart.TeeChartFragment.onCreateView(TeeChartFragment.java:43)
    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1504)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:942)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1121)
    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1484)
    at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:571)
    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
    at android.app.Activity.performStart(Activity.java:5241)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2157)
    ... 11 more
下面是我发现的一个类似问题的例子:http://www.teechart.net/support/viewtopic.php?f=4& t = 8092, p = 32273, hilit = drawAxisLabel # p32273

谁能建议如何绕过我的问题?

在你引用的例子中,直接绘图函数必须在绘制组件后调用,最好是在AfterDraw/chartPainted事件中。
下面的代码对我来说很好:

tChart1.addChartPaintListener(new ChartPaintAdapter() {
    @Override
    public void chartPainted(ChartDrawEvent e) {
        Axis leftAxis = tChart1.getAxes().getLeft();
        TextShape label = new TextShape(tChart1.getChart());
        leftAxis.drawAxisLabel(leftAxis.getPosition(), leftAxis.calcPosValue(500), 0, "CLOSE", label);
    }
});

相关内容

  • 没有找到相关文章

最新更新