Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在androidplot条形图中绘制不同颜色的条形图?_Android_Androidplot - Fatal编程技术网

如何在androidplot条形图中绘制不同颜色的条形图?

如何在androidplot条形图中绘制不同颜色的条形图?,android,androidplot,Android,Androidplot,1.我的柱状图有一个系列 2.在意甲有10个值 3.当显示图表时,它有10个条,但所有条颜色相同 4.如何绘制不同颜色的酒吧 我正试着这么做,但没用 class MyBarRenderer extends BarRenderer<MyBarFormatter> { public MyBarRenderer(XYPlot plot) { super(plot); } protected BarFormatter getFormatter(int

1.我的柱状图有一个系列

2.在意甲有10个值

3.当显示图表时,它有10个条,但所有条颜色相同

4.如何绘制不同颜色的酒吧

我正试着这么做,但没用

class MyBarRenderer extends BarRenderer<MyBarFormatter> {
    public MyBarRenderer(XYPlot plot) {
        super(plot);
    }

    protected BarFormatter getFormatter(int index, XYSeries series) {
        //return getFormatter(series);
        if(index % 2 == 1) {
            return new MyBarFormatter(Color.BLUE, Color.TRANSPARENT);
        } else {
            return new MyBarFormatter(Color.RED, Color.TRANSPARENT);
        }
    }
}
类MyBallenderer扩展了Ballenderer{
公共密码表(XYPlot){
超级(情节);
}
受保护的BarFormatter getFormatter(int索引,XYSeries系列){
//返回getFormatter(系列);
如果(索引%2==1){
返回新的MyBarFormatter(Color.BLUE,Color.TRANSPARENT);
}否则{
返回新的MyBarFormatter(Color.RED,Color.TRANSPARENT);
}
}
}

我的代码看起来和你的几乎一模一样,它对我很有用。以下是我的代码的其余部分:

class MyBarFormatter extends BarFormatter
{
    public MyBarFormatter(int fillColor, int borderColor)
    {
        super(fillColor, borderColor);
    }

    @Override public Class<? extends SeriesRenderer> getRendererClass()
    {
        return MyBarRenderer.class;
    }

    @Override public SeriesRenderer getRendererInstance(XYPlot plot)
    {
        return new MyBarRenderer(plot);
    }
}

class MyBarRenderer extends BarRenderer<MyBarFormatter>
{
    public MyBarRenderer(XYPlot plot)
    {
        super(plot);
    }

    public MyBarFormatter getFormatter(int index, XYSeries series)
    {
        // return getFormatter(series);
        if(index % 2 == 1)
        {
            return new MyBarFormatter(Color.BLUE, Color.TRANSPARENT);
        }
        else
        {
            return new MyBarFormatter(Color.RED, Color.TRANSPARENT);
        }
    }
}
下面是它的外观,在两种不同颜色之间交替:

此外,要添加水平虚线,请执行以下操作:

YValueMarker yValueMarker = new YValueMarker(2300, "", new XPositionMetric(PixelUtils.dpToPix(0), XLayoutStyle.ABSOLUTE_FROM_RIGHT), Color.BLACK, Color.BLACK);

DashPathEffect dashPathEffect = new DashPathEffect(new float[] { PixelUtils.dpToPix(16), PixelUtils.dpToPix(8) }, 0);

yValueMarker.getLinePaint().setPathEffect(dashPathEffect);

yValueMarker.getLinePaint().setStrokeWidth(PixelUtils.dpToPix(1));

yValueMarker.getLinePaint().setColor(Color.BLACK);

addMarker(yValueMarker);

你是如何在2000-2500范围内画出水平虚线的?@ManuelLopera我刚刚在我的答案底部添加了代码。
YValueMarker yValueMarker = new YValueMarker(2300, "", new XPositionMetric(PixelUtils.dpToPix(0), XLayoutStyle.ABSOLUTE_FROM_RIGHT), Color.BLACK, Color.BLACK);

DashPathEffect dashPathEffect = new DashPathEffect(new float[] { PixelUtils.dpToPix(16), PixelUtils.dpToPix(8) }, 0);

yValueMarker.getLinePaint().setPathEffect(dashPathEffect);

yValueMarker.getLinePaint().setStrokeWidth(PixelUtils.dpToPix(1));

yValueMarker.getLinePaint().setColor(Color.BLACK);

addMarker(yValueMarker);