3

我想在我的条形图顶部有一个不同的文本值。该值不同,因为我想要一种对数缩放。我怎样才能做到这一点?非常感谢。

我搜索了其他问题,但所有这些问题都超过一年,我找不到任何最新信息:(

添加 series.addAnnotation(...); 后的新异常;

代码

public GraphicalView getView(Context context, List<Double> height, List<String> text, List<String> time) {

    XYSeries series = new XYSeries(null);
    for(int i = 0; i < height.size(); i++) {
        series.add(i, height.get(i));
        series.addAnnotation(text.get(i), (double) i, height.get(i));
    }
    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
    dataset.addSeries(series);

    XYSeriesRenderer renderer = new XYSeriesRenderer();     
    //renderer.setDisplayChartValues(true);
    renderer.setColor(Color.parseColor("#3399cc"));

    XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
    mRenderer.addSeriesRenderer(renderer);

    ...

例外

    06-11 13:49:49.256: E/AndroidRuntime(18424): FATAL EXCEPTION: main
    06-11 13:49:49.256: E/AndroidRuntime(18424): java.lang.NullPointerException
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at org.achartengine.chart.XYChart.draw(XYChart.java:305)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at org.achartengine.GraphicalView.onDraw(GraphicalView.java:168)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.draw(View.java:13776)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.getDisplayList(View.java:12727)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.getDisplayList(View.java:12771)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.draw(View.java:13500)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.ViewGroup.drawChild(ViewGroup.java:3171)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3041)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.getDisplayList(View.java:12725)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.getDisplayList(View.java:12771)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.draw(View.java:13500)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.ViewGroup.drawChild(ViewGroup.java:3171)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3041)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.getDisplayList(View.java:12725)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.getDisplayList(View.java:12771)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.draw(View.java:13500)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.ViewGroup.drawChild(ViewGroup.java:3171)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3041)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.draw(View.java:13779)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.widget.FrameLayout.draw(FrameLayout.java:467)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.widget.ScrollView.draw(ScrollView.java:1821)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.getDisplayList(View.java:12727)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.getDisplayList(View.java:12771)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.draw(View.java:13500)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.ViewGroup.drawChild(ViewGroup.java:3171)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3041)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.draw(View.java:13779)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.getDisplayList(View.java:12727)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.getDisplayList(View.java:12771)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.draw(View.java:13500)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.ViewGroup.drawChild(ViewGroup.java:3171)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3041)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.draw(View.java:13779)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.widget.FrameLayout.draw(FrameLayout.java:467)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.getDisplayList(View.java:12727)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.getDisplayList(View.java:12771)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.draw(View.java:13500)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.ViewGroup.drawChild(ViewGroup.java:3171)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3041)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.getDisplayList(View.java:12725)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.getDisplayList(View.java:12771)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.draw(View.java:13500)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.ViewGroup.drawChild(ViewGroup.java:3171)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3041)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.draw(View.java:13779)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.widget.FrameLayout.draw(FrameLayout.java:467)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2420)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.getDisplayList(View.java:12727)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.View.getDisplayList(View.java:12771)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1144)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.ViewRootImpl.draw(ViewRootImpl.java:2278)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2150)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1961)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1115)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4526)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.Choreographer.doCallbacks(Choreographer.java:555)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.Choreographer.doFrame(Choreographer.java:525)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.os.Handler.handleCallback(Handler.java:615)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.os.Handler.dispatchMessage(Handler.java:92)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.os.Looper.loop(Looper.java:137)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at android.app.ActivityThread.main(ActivityThread.java:4921)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at java.lang.reflect.Method.invokeNative(Native Method)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at java.lang.reflect.Method.invoke(Method.java:511)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
    06-11 13:49:49.256: E/AndroidRuntime(18424):    at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

2

您拥有的选项与注释有关。为每个条添加一个,如下所示:

series.addAnnotation("text", x, y);
于 2013-06-11T09:49:18.833 回答