在 MPAndroidChart 中自定义图例 [英] customize Legend in MPAndroidChart

查看:55
本文介绍了在 MPAndroidChart 中自定义图例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在需要实现图表的项目中工作,我决定使用

解决方案

如果你创建一个自定义的Chart 类并覆盖 init().在这个方法中,Chart 初始化了一个 LegendRenderer,这是您需要进入并进行更改的重点.

创建自定义LegendRenderer 并确保所有可绘制对象的测量都到位.drawForm() 方法将允许您绘制图像而不是默认形式(圆形、方形、线).

I am working in project in project that needs implement chart , I decide use MPAndroidChart its work just fine but I need some things done to be perfect to me

First can I change bars to specific image or it takes just images , as I have 3D image as bars in app design .

Second Can I put the legend to the right of chart in two line like image below and change legend text color

my java code

mChart = (BarChart) view.findViewById(R.id.chart);
        mChart.setDescription("");
        Legend mLegend = mChart.getLegend();
        //mLegend.setPosition(Legend.LegendPosition.RIGHT_OF_CHART_CENTER);
FillBarChart(mChart);
}


private void FillBarChart(BarChart barChart) {
        ArrayList<BarEntry> entries = new ArrayList<>();
        entries.add(new BarEntry(87f, 0));
        entries.add(new BarEntry(90f, 1));


        ArrayList<String> labels = new ArrayList<>();
        labels.add("Omeprazole 20 mg");
        labels.add("Esomeprazole 40 mg");

        BarDataSet dataSet = new BarDataSet(entries, " ");
        dataSet.setBarSpacePercent(40f);
        BarData barData = new BarData(labels, dataSet);
        dataSet.setColors(new int[]{R.color.omeprazole_color , R.color.esomeprazole_color} , getActivity());
        barChart.setData(barData);
        barChart.animateY(3000 , Easing.EasingOption.EaseOutBack );
    }

解决方案

You can do that if you create a custom Chart class and overwrite the init(). In this method, the Chart initializes a LegendRenderer and this is the point you need to get in and make changes.

Create a custom LegendRenderer and make sure that all the measurements are in place for those drawable. drawForm() method will allow you to draw the images instead of the default forms (Circle, Square, Line).

这篇关于在 MPAndroidChart 中自定义图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆