2

I am plotting the wind direction as a xyseries in a TimeChartView using aChartEngine along with windspeed (windspeed is a timeseries using left y-axis, winddir is XYSeries using right y-axis).

The problem I am facing is that as the windirection passes north, my values shift between 0 and 360, creating an ugly vertical line in my graph. I would prefer that if the values increased above 360 the graph just got clipped and resumed at 0. By filtering the values and inserting MathHelper.NULL_VALUE in my XYSeries (see code) I managed to get the graph as I wanted

 double windDirTemp=0; 

...

    if (Math.abs(windDirValues[k] - windDirTemp)>300 ){
                windDirTemp = windDirValues[k];     
                windDirSeries.add(convertedDateinDouble[k], MathHelper.NULL_VALUE );                
            }
            else{
                windDirSeries.add(convertedDateinDouble[k], windDirValues[k]);
            }   

The problem now is that my OnClickListener doesn't work anymore. The app crashes on

SeriesSelection seriesSelection = mChart.getCurrentSeriesAndPoint();

I assume that inserting the null-values to my series makes getCurrentSeriesAndPoint unable to get the SeriesIndex and can have something to do with the graph no longer being connected.

I would greatly appreciate any help to solve this. Could I filter the values differently? Is there an alternative to getCurrentSeriesAndPoint() I could try?

Thanks, Christian

EDIT:

I am using achartengine-1.1.0-rc2

My OneClickListener:

/**
         * Setting a click event listener for the graph
         */
        mChart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Format formatter = new SimpleDateFormat("HH:mm");

                SeriesSelection seriesSelection = mChart.getCurrentSeriesAndPoint();                

                if (seriesSelection != null) {
                    int seriesIndex = seriesSelection.getSeriesIndex();
                    String selectedSeries = "Vindhastighet";
                    String unit = " m/s";

                    if (seriesIndex == 0)
                        selectedSeries = "Vindhastigheten";
                    else if (seriesIndex == 1)
                        selectedSeries = "Vindkast";
                    else {
                        selectedSeries = "Vindretningen";
                        unit = "\u00B0";
                    }

                    // Getting the clicked Date ( x value )
                    long clickedDateSeconds = (long) seriesSelection
                            .getXValue();
                    Date clickedDate = new Date(clickedDateSeconds);
                    String strDate = formatter.format(clickedDate);

                    // Getting the y value
                    int amount = (int) seriesSelection.getValue();

                    // Displaying Toast Message
                    Toast.makeText(
                            getBaseContext(),
                            selectedSeries + " kl " + strDate + " var "
                                    + amount + unit, Toast.LENGTH_LONG)
                            .show();
                }                   
            }
        });

My logcat:

04-02 16:05:18.575: E/AndroidRuntime(29182): FATAL EXCEPTION: main 04-02 16:05:18.575: E/AndroidRuntime(29182): java.lang.NullPointerException 04-02 16:05:18.575: E/AndroidRuntime(29182): at org.achartengine.chart.XYChart.getSeriesAndPointForScreenCoordinate(XYChart.java:845) 04-02 16:05:18.575: E/AndroidRuntime(29182): at org.achartengine.GraphicalView.getCurrentSeriesAndPoint(GraphicalView.java:137) 04-02 16:05:18.575: E/AndroidRuntime(29182): at com.example.hellogooglemaps.WindChartActivity$1.onClick(WindChartActivity.java:116) 04-02 16:05:18.575: E/AndroidRuntime(29182): at android.view.View.performClick(View.java:4211) 04-02 16:05:18.575: E/AndroidRuntime(29182): at android.view.View$PerformClick.run(View.java:17267) 04-02 16:05:18.575: E/AndroidRuntime(29182): at android.os.Handler.handleCallback(Handler.java:615) 04-02 16:05:18.575: E/AndroidRuntime(29182): at android.os.Handler.dispatchMessage(Handler.java:92) 04-02 16:05:18.575: E/AndroidRuntime(29182): at android.os.Looper.loop(Looper.java:137) 04-02 16:05:18.575: E/AndroidRuntime(29182): at android.app.ActivityThread.main(ActivityThread.java:4898) 04-02 16:05:18.575: E/AndroidRuntime(29182): at java.lang.reflect.Method.invokeNative(Native Method) 04-02 16:05:18.575: E/AndroidRuntime(29182): at java.lang.reflect.Method.invoke(Method.java:511) 04-02 16:05:18.575: E/AndroidRuntime(29182): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006) 04-02 16:05:18.575: E/AndroidRuntime(29182): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773) 04-02 16:05:18.575: E/AndroidRuntime(29182): at dalvik.system.NativeStart.main(Native Method)

6
  • Maybe it would help to show us your OnClickListener´s code and the stacktrace? Apr 2, 2013 at 13:25
  • I suggest you update to the latest version: repository-achartengine.forge.cloudbees.com/snapshot/org/…
    – Dan D.
    Apr 2, 2013 at 16:30
  • @Dan: Thanks for the latest version:) You're doing a great job! However the problem still persists and my logcat reports the same error...
    – Fubbe99
    Apr 2, 2013 at 17:07
  • Please post a small example that I can use to replicate the issue. If there is a bug, I will fix it, but I need a test case that replicates it.
    – Dan D.
    Apr 3, 2013 at 13:07
  • 1
    @Dan I have checked to confirm that if I swap the values with for example double[] visits = { 2000, 2500, MathHelper.NULL_VALUE, 2100, 2800}; double[] views = {2200, 2700, 2900, 2800, 3200}; the app crashes with the same error report. I need to set multiRenderer.setYAxisMin(0); multiRenderer.setYAxisMax(4000); to see the data.
    – Fubbe99
    Apr 3, 2013 at 18:51

1 Answer 1

1

This was a bug in AChartEngine and is now fixed. You can download a version including this fix here.

2
  • 1
    I'm still having this issue in my code. It seems to work at some points and not for others. Is it possible that it doesn't work on interpolated parts of the graph? Thanks.
    – Ran
    Sep 25, 2013 at 11:36
  • Hello @Dan i have this type value. double[] X = { 1, 2,3 , 4 ,5}; double[] Y = {2200, MathHelper.NULL_VALUE, 2900, MathHelper.NULL_VALUE, 3200}; so here i want to draw line but skip null value where need gap and draw line between where value so what i do ? Jan 23, 2017 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.