English 中文(简体)
采用从数据库获得的远程数据编制图表
原标题:Generating graph by using remote data from database on achartengine

I am trying to generate a graph using achartengine which pulls the data from a database and populates the graph using the data. Following is the code that populates the graph. All tha data is stored in

"dataArraylist". This code populates the data into graph

        CategorySeries series = new CategorySeries("Bar Graph");     //"series" = graph
        for(int i=0; i< size; i++)
        {
            series.add("Bar"+(i+1), dataArraylist.get(i));                      //add each of the value to the series i.e graph
        }


        XYMultipleSeriesDataset dataset= new XYMultipleSeriesDataset(); 
        dataset.addSeries(series.toXYSeries());                                       //add the graph into a dataset


        // customisation for the first line
        XYSeriesRenderer renderer = new XYSeriesRenderer();
        renderer.setDisplayChartValues(true);
        renderer.setChartValuesSpacing((float) 0.5);
        renderer.setColor(Color.WHITE);

        XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer(); //create a new renderer.
        mRenderer.addSeriesRenderer(renderer); //renderer lets one to change the proerties of the graph i.e line colour etc
        mRenderer.setXTitle("X VALUES");
        mRenderer.setXTitle("Y VALUES");

        mRenderer.setChartTitle("This is title");

        Intent intent = ChartFactory.getBarChartIntent(context, dataset, mRenderer,Type.DEFAULT, "Title"); //package the whole chart together


        return intent;

然而,在试图将其汇编成册时,我会发现“Null”例外错误,其内容如下:

                       04-07 21:09:31.713: E/AndroidRuntime(4091): java.lang.IllegalStateException: Could not execute method of the activity

我在将一个活动的数据传送到图表活动方面也存在问题。 请作出答复。

完整记录为:

                   04-07 21:09:31.674: D/AndroidRuntime(4091): Shutting down VM
04-07 21:09:31.674: W/dalvikvm(4091): threadid=1: thread exiting with uncaught exception (group=0x40015560)
04-07 21:09:31.713: E/AndroidRuntime(4091): FATAL EXCEPTION: main
04-07 21:09:31.713: E/AndroidRuntime(4091): java.lang.IllegalStateException: Could not execute method of the activity
04-07 21:09:31.713: E/AndroidRuntime(4091):     at android.view.View$1.onClick(View.java:2144)
04-07 21:09:31.713: E/AndroidRuntime(4091):     at android.view.View.performClick(View.java:2485)
04-07 21:09:31.713: E/AndroidRuntime(4091):     at android.view.View$PerformClick.run(View.java:9080)
04-07 21:09:31.713: E/AndroidRuntime(4091):     at android.os.Handler.handleCallback(Handler.java:587)
04-07 21:09:31.713: E/AndroidRuntime(4091):     at android.os.Handler.dispatchMessage(Handler.java:92)
04-07 21:09:31.713: E/AndroidRuntime(4091):     at android.os.Looper.loop(Looper.java:123)
04-07 21:09:31.713: E/AndroidRuntime(4091):     at android.app.ActivityThread.main(ActivityThread.java:3683)
04-07 21:09:31.713: E/AndroidRuntime(4091):     at java.lang.reflect.Method.invokeNative(Native Method)
04-07 21:09:31.713: E/AndroidRuntime(4091):     at java.lang.reflect.Method.invoke(Method.java:507)
04-07 21:09:31.713: E/AndroidRuntime(4091):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-07 21:09:31.713: E/AndroidRuntime(4091):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-07 21:09:31.713: E/AndroidRuntime(4091):     at dalvik.system.NativeStart.main(Native Method)
04-07 21:09:31.713: E/AndroidRuntime(4091): Caused by: java.lang.reflect.InvocationTargetException
04-07 21:09:31.713: E/AndroidRuntime(4091):     at java.lang.reflect.Method.invokeNative(Native Method)
04-07 21:09:31.713: E/AndroidRuntime(4091):     at java.lang.reflect.Method.invoke(Method.java:507)
04-07 21:09:31.713: E/AndroidRuntime(4091):     at android.view.View$1.onClick(View.java:2139)
04-07 21:09:31.713: E/AndroidRuntime(4091):     ... 11 more
04-07 21:09:31.713: E/AndroidRuntime(4091): Caused by: java.lang.NullPointerException
04-07 21:09:31.713: E/AndroidRuntime(4091):     at hudds.fc.coach.ReadinessGraph.getIntent(ReadinessGraph.java:45)
04-07 21:09:31.713: E/AndroidRuntime(4091):     at hudds.fc.coach.Overview.generateGraph(Overview.java:101)
04-07 21:09:31.713: E/AndroidRuntime(4091):     ... 14 more
04-07 21:09:34.746: I/Process(4091): Sending signal. PID: 4091 SIG: 9

在编码下载数据库数据之后:

        try {
        if (json.getString(KEY_SUCCESS) != null) {

            String getsize=json.getString("size");
            size = Integer.parseInt(getsize);

            for (int i = 0; i < size; i++) { 
            String getRating=json.getJSONArray("number").getJSONObject(i).getString("rating_number");
            int rating = Integer.parseInt(getRating);


            readinessRatng.add(rating);
            String printratings=readinessRatng.toString();
            Log.e("ratings are", printratings);
            }

        }


    else{

                     }
        }

    catch (JSONException e) {
        e.printStackTrace();
            }
最佳回答

Refer this LINK forachartengine

 public XYMultipleSeriesRenderer getBarDemoRenderer() {
    XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
    renderer.setAxisTitleTextSize(16);
    renderer.setChartTitleTextSize(20);
    renderer.setLabelsTextSize(15);
    renderer.setLegendTextSize(15);
    renderer.setMargins(new int[] {20, 30, 15, 0});
    SimpleSeriesRenderer r = new SimpleSeriesRenderer();
    r.setColor(Color.BLUE);
    renderer.addSeriesRenderer(r);
    r = new SimpleSeriesRenderer();
    r.setColor(Color.GREEN);
    renderer.addSeriesRenderer(r);
    return renderer;
  }

 private XYMultipleSeriesDataset getBarDemoDataset() {
    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
    final int nr = 10;
    Random r = new Random();
    for (int i = 0; i < SERIES_NR; i++) {
      CategorySeries series = new CategorySeries("Demo series " + (i + 1));
      for (int k = 0; k < nr; k++) {
        series.add(100 + r.nextInt() % 100);
      }
      dataset.addSeries(series.toXYSeries());
    }
    return dataset;
  }



private void setChartSettings(XYMultipleSeriesRenderer renderer) {
    renderer.setChartTitle("Chart demo");
    renderer.setXTitle("x values");
    renderer.setYTitle("y values");
    renderer.setXAxisMin(0);
    renderer.setXAxisMax(5);
    renderer.setYAxisMin(0);
    renderer.setYAxisMax(250);
  }

添加上述方法,并从您的立国方法中划出以下线:

XYMultipleSeriesRenderer renderer = getBarDemoRenderer();
setChartSettings(renderer);
Intent intent = ChartFactory.getBarChartIntent(this, getBarDemoDataset(), renderer, Type.DEFAULT);
startActivity(intent);
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签