Android的 - aChartEngine getCurrentSeriesAndPoint()不工作的断开图 [英] Android - aChartEngine getCurrentSeriesAndPoint() not working for disconnected graph
问题描述
我是在一个TimeChartView使用xyseries与aChartEngine沿风速(风速是采用左侧y轴的时间序列,winddir是使用权y轴XYSeries)绘制风向。
我现在面临的问题是,由于windirection经过北方,我值0和360之间切换,创造了我的图形中的丑陋的垂直线上。我想preFER,如果值高于360增加了图形刚刚修剪,并在0恢复通过过滤值,并在我的XYSeries插入MathHelper.NULL_VALUE(见$ C $三)我设法得到图作为我想
双windDirTemp = 0;
...
如果(Math.abs(windDirValues [K] - windDirTemp)高于300){
windDirTemp = windDirValues [K];
windDirSeries.add(convertedDateinDouble [k]的,MathHelper.NULL_VALUE);
}
其他{
windDirSeries.add(convertedDateinDouble [K],windDirValues [K]);
}
现在的问题是,我的OnClickListener不再工作了。在应用程序崩溃
SeriesSelection seriesSelection = mChart.getCurrentSeriesAndPoint();
我认为插入空值到我的系列产品让getCurrentSeriesAndPoint无法得到SeriesIndex,可以有事情做与不再连接图。
我将不胜AP preciate任何帮助解决这个问题。我可以过滤不同的价值观?是否有getCurrentSeriesAndPoint()我可以尝试?
替代谢谢,
基督教
编辑:
我使用achartengine-1.1.0-RC2
我OneClickListener:
/ **
*设置一个点击事件侦听器图
* /
mChart.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v){
格式格式化=新的SimpleDateFormat(HH:MM); SeriesSelection seriesSelection = mChart.getCurrentSeriesAndPoint(); 如果(seriesSelection!= NULL){
INT seriesIndex = seriesSelection.getSeriesIndex();
字符串selectedSeries =Vindhastighet;
串单元=米/秒; 如果(seriesIndex == 0)
selectedSeries =Vindhastigheten;
否则如果(seriesIndex == 1)
selectedSeries =Vindkast;
其他{
selectedSeries =Vindretningen;
单位=\\ u00B0
} //获取点击的日期(x值)
长clickedDateSeconds =(长)seriesSelection
.getXValue();
日期clickedDate =新的日期(clickedDateSeconds);
字符串strDate = formatter.format(clickedDate); //获取y值
INT量=(int)的seriesSelection.getValue(); //显示吐司留言
Toast.makeText(
getBaseContext(),
selectedSeries +KL+ strDate +VAR
+量+单元,Toast.LENGTH_LONG)
。显示();
}
}
});
我的logcat的:
16 04-02:05:18.575:E / AndroidRuntime(29182):致命异常:主要
04-02 16:05:18.575:E / AndroidRuntime(29182):显示java.lang.NullPointerException
04-02 16:05:18.575:E / AndroidRuntime(29182):在org.achartengine.chart.XYChart.getSeriesAndPointForScreenCoordinate(XYChart.java:845)
04-02 16:05:18.575:E / AndroidRuntime(29182):在org.achartengine.GraphicalView.getCurrentSeriesAndPoint(GraphicalView.java:137)
04-02 16:05:18.575:E / AndroidRuntime(29182):在com.example.hellogooglemaps.WindChartActivity $ 1.onClick(WindChartActivity.java:116)
04-02 16:05:18.575:E / AndroidRuntime(29182):在android.view.View.performClick(View.java:4211)
04-02 16:05:18.575:E / AndroidRuntime(29182):在android.view.View $ PerformClick.run(View.java:17267)
04-02 16:05:18.575:E / AndroidRuntime(29182):在android.os.Handler.handleCallback(Handler.java:615)
04-02 16:05:18.575:E / AndroidRuntime(29182):在android.os.Handler.dispatchMessage(Handler.java:92)
04-02 16:05:18.575:E / AndroidRuntime(29182):在android.os.Looper.loop(Looper.java:137)
04-02 16:05:18.575:E / AndroidRuntime(29182):在android.app.ActivityThread.main(ActivityThread.java:4898)
04-02 16:05:18.575:E / AndroidRuntime(29182):在java.lang.reflect.Method.invokeNative(本机方法)
04-02 16:05:18.575:E / AndroidRuntime(29182):在java.lang.reflect.Method.invoke(Method.java:511)
04-02 16:05:18.575:E / AndroidRuntime(29182):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1006)
04-02 16:05:18.575:E / AndroidRuntime(29182):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
04-02 16:05:18.575:E / AndroidRuntime(29182):在dalvik.system.NativeStart.main(本机方法)
块引用>解决方案这是AChartEngine一个bug,现在是固定的。您可以下载包括此修订<一个版本href=\"https://repository-achartengine.forge.cloudbees.com/snapshot/org/achartengine/achartengine/1.1.0/\"相对=nofollow>这里。
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)
解决方案This was a bug in AChartEngine and is now fixed. You can download a version including this fix here.
这篇关于Android的 - aChartEngine getCurrentSeriesAndPoint()不工作的断开图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!