使用Java中的绘画为圆内的圆填充不同的颜色

时间:2018-09-04 10:47:41

标签: java android paint

enter image description here

我正在使用jjoe64:graphview库在Android中绘制图形。正如您在所附图像中看到的那样,我希望数据点在圆内圆,并为圆具有不同的填充颜色。

我能够在圆圈内绘制圆圈,但无法弄清楚如何为圆圈设置不同的颜色。

这是我的代码

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        GraphView graphView = findViewById(R.id.graph);
        LineGraphSeries<DataPoint> series = new LineGraphSeries<>(new DataPoint[]{
            new DataPoint(0.0,10),
                new DataPoint(1.0,1),
                new DataPoint(2.0,9),
                new DataPoint(3.0,4),
                new DataPoint(4.0,3),
                new DataPoint(5.0,1),
                new DataPoint(6.0,10),
                new DataPoint(7.0,15),
                new DataPoint(8.0,16),
                new DataPoint(9.0,23),
                new DataPoint(10.0,22),
                new DataPoint(11.0,11),
                new DataPoint(12.0,10),
                new DataPoint(13.0,0)
        });

        series.setTitle("Random Curve 1");
        series.setColor(getResources().getColor(R.color.colorAccent));
        series.setThickness(8);

        graphView.getGridLabelRenderer().setNumVerticalLabels(10);
        graphView.getGridLabelRenderer().setNumHorizontalLabels(10);
        graphView.addSeries(series);

        PointsGraphSeries<DataPoint> series1 = new PointsGraphSeries<>(new DataPoint[]{
                new DataPoint(0.0,10),
                new DataPoint(1.0,1),
                new DataPoint(2.0,9),
                new DataPoint(3.0,4),
                new DataPoint(4.0,3),
                new DataPoint(5.0,1),
                new DataPoint(6.0,10),
                new DataPoint(7.0,15),
                new DataPoint(8.0,16),
                new DataPoint(9.0,23),
                new DataPoint(10.0,22),
                new DataPoint(11.0,11),
                new DataPoint(12.0,10),
                new DataPoint(13.0,0)
        });
        series1.setShape(PointsGraphSeries.Shape.POINT);
//        series1.setShape();
        series1.setCustomShape(new PointsGraphSeries.CustomShape() {
            @Override
            public void draw(Canvas canvas, Paint paint, float x, float y, DataPointInterface dataPoint) {
                paint.setStyle(Paint.Style.STROKE);
                for(int i=0;i<2;i++){
                    canvas.drawCircle(x,y,5+(i*2),paint);
                }
//                paint.setColor(getResources().getColor(android.R.color.black));
            }
        });
        series1.setSize(10);
        graphView.addSeries(series1);


    }

在圆内绘制圆的代码在series1.setCustomShape方法中。可以使用Android XML进行绘制并将其附加到数据点吗?

0 个答案:

没有答案