Is it possible to hide points on an Androidplot XYplot?

£可爱£侵袭症+ 提交于 2019-12-11 05:25:33

问题


1) I have an Androidplot XYPlot and some values are 0 to represent "no data" on that point. Can I hide these points with value "0" from the plot?

2) If I can't hide them, can I make the graph lines going from the previous point, to the 0 value point and to the next point, another color (like red) to show that this is a point "with no data"?


回答1:


XYPlot's underlying model is XYSeries which uses Numbers to represent points. If you're implementing your own XYSeries then just return null from getX(i) / getY(i) where i is the index of any "no data" element.

If you're using SimpleXYSeries, then just pass null into the constructor, model or setX/Y method you're using to populate it.

When the plot is drawn, you should see your line(s) broken up where nulls are encountered.




回答2:


After pondering Nicks answer I got it working:

plot = (XYPlot) findViewById(R.id.mySimpleXYPlot);

// nums is an array holding different numbers, where some are 0.

Number Nullnumber = null;

SimpleXYSeries series1test;
series1test = new SimpleXYSeries("title");

for (int j = 0; j < nums.length; j++){

    if(nums[j]==0){
        series1test.addLast(j, Nullnumber); // Does not display points for 0 values
        //series1test.addLast(j, nums[j]);  // Displays points for 0 values
    } else {
        series1test.addLast(j, nums[j]);
    }
}

LineAndPointFormatter series1Format = new LineAndPointFormatter();
series1Format.setPointLabelFormatter(new PointLabelFormatter());
series1Format.configure(getApplicationContext(),
R.xml.line_point_formatter_with_plf1);

plot.addSeries(series1test, series1Format); 


来源:https://stackoverflow.com/questions/24210061/is-it-possible-to-hide-points-on-an-androidplot-xyplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!