GraphView中的虚线

时间:2017-07-16 12:27:28

标签: java android android-custom-view paint android-graphview

我想要一条虚线,如the official documentation

中所述
    futureSeries.setDrawDataPoints(true);

    Paint paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(10);
    paint.setPathEffect(new DashPathEffect(new float[]{8, 5}, 0));
    futureSeries.setCustomPaint(paint);

    graph.addSeries(futureSeries);

的build.gradle:

   compile 'com.jjoe64:graphview:4.2.1'

结果不是虚线:

enter image description here

这样的事情就可以了:

enter image description here

1 个答案:

答案 0 :(得分:5)

只需应用LineGraphSeries#setDrawAsPath(true)

Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(10);
paint.setPathEffect(new DashPathEffect(new float[]{8, 5}, 0));

LineGraphSeries<DataPoint> series = ... // init

series.setDrawAsPath(true);
series.setCustomPaint(paint);

graphView.addSeries(series);

结果:

enter image description here