问题
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