我正在努力做到这一点:
http://s11.postimg.org/4jfa3bpxf/graph.png,
到目前为止我有:
http://s23.postimg.org/4tizcnqyj/current_graph.png
(没关系颜色,这是为了更容易识别不同的组件)。
我有几个问题:
- 我想移动范围标签,但似乎 myPlot.getRangeLabelWidget().position(<...>) 没有移动它们
- 如何使灰色区域(白色图形和红色边框之间)消失?我尝试使用所有边距/填充但没有成功
- 如何只保留1条蓝色虚线?(中间那个)。我可以使用边距使其消失,但是数字 10.0 也会消失
- 要删除域标签,最好将标签颜色设置为透明,还是使小部件不可见?
提前致谢!
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.chart, container, false);
plot = (XYPlot) view.findViewById(R.id.mySimpleXYPlot);
Number[] series1Numbers = {3, 8, 5, 2, 7, 4};
XYSeries series1 = new SimpleXYSeries(
Arrays.asList(series1Numbers),
SimpleXYSeries.ArrayFormat.Y_VALS_ONLY,
"");
LineAndPointFormatter series1Format = new LineAndPointFormatter();
series1Format.setPointLabelFormatter(new PointLabelFormatter());
series1Format.configure(getActivity().getApplicationContext(), R.xml.line_point_formatter_with_plf1);
plot.addSeries(series1, series1Format);
plot.getLegendWidget().setVisible(false); // remove legend
plot.setRangeStep(XYStepMode.SUBDIVIDE, 3);
plot.setDomainStep(XYStepMode.SUBDIVIDE, 1);
plot.getGraphWidget().getDomainLabelPaint().setColor(Color.TRANSPARENT);
plot.getGraphWidget().getDomainOriginLabelPaint().setColor(Color.TRANSPARENT);
plot.getGraphWidget().getBackgroundPaint().setColor(Color.WHITE);
plot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE);
plot.setRangeBottomMax(0);
plot.setRangeTopMin(10);
plot.getGraphWidget().getDomainGridLinePaint().setColor(Color.BLACK);
plot.getGraphWidget().getRangeGridLinePaint().setColor(Color.BLUE);
plot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.GREEN);
plot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.YELLOW);
plot.getGraphWidget().getRangeGridLinePaint().setPathEffect(new DashPathEffect(new float[]{6, 10}, 1));
plot.getGraphWidget().getRangeOriginLabelPaint().setColor(Color.GREEN);
plot.getGraphWidget().getRangeLabelPaint().setColor(Color.RED);
plot.getBorderPaint().setColor(Color.RED);
plot.setPlotMargins(0, 0, 0, 0);
plot.setPlotPadding(0, 0, 0, 0);
plot.getGraphWidget().position(
0, XLayoutStyle.ABSOLUTE_FROM_LEFT,
0, YLayoutStyle.ABSOLUTE_FROM_TOP,
AnchorPosition.LEFT_TOP);
plot.getRangeLabelWidget().position(
50, XLayoutStyle.ABSOLUTE_FROM_LEFT,
50, YLayoutStyle.ABSOLUTE_FROM_TOP,
AnchorPosition.LEFT_TOP);
//plot.redraw();
return view;
}