本文介绍了将特定颜色设置为LineChart占用的区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够动态绘制标记并将LineChart设置为其他颜色.现在我遇到问题,无法在LineChart所在的区域填充颜色.我使用了 setS.setDrawFilled(true ); ,但只能填充一种颜色.如何解决此问题?

I am able to plot Marks Dynamically and set Different Color to the LineChart.Now i am having issue of, not able to fill the Color in the Region where the LineChart occupies.I have used setS.setDrawFilled(true); but it Fill with only one Color.How can this issue be Solved?

  int getColorRandom() {
        Random rand = new Random();
        int r = rand.nextInt(255);
        int g = rand.nextInt(255);
        int b = rand.nextInt(255);
        int randomColor = Color.rgb(r, g, b);
        return randomColor;

    }

  ArrayList<ILineDataSet> testDataSet1 = new ArrayList<>();
                            for (int i = 0; i < dataFilteredByTerm.size(); i++) {
                                ArrayList<JSONObject> values = dataFilteredByTerm.get(termIDs.get(i));
                                ArrayList<Entry> allMarks1 = new ArrayList<>();


                                for (int k = 0; k < values.size(); k++) {
                                    allMarks1.add(new Entry(k, values.get(k).optInt("Marks")));

                                }

                                Labels.add(jsonArray.optJSONObject(i).optString("CourseName"));
                                System.out.println("Labels" + Labels);
                                // System.out.println("allMarks" + allMarks1);
                                setS = new LineDataSet(allMarks1, values.get(i).optString("examDescription")); // set different color for each set as your requirement testDataSet.add(set); } chart.setData(new LineData(testDataSet));
                                //testDataSet1.add(labels);


                                testDataSet1.add(setS);
                                setS.setMode(LineDataSet.Mode.CUBIC_BEZIER);
                                setS.setDrawValues(false);
                                // setS.setColor(Integer.parseInt((getColor.get(i))));
                                // int y= setS.setColors(getColor());
                                setS.setDrawFilled(true);
                                setS.setColors(getColorRandom());


                            }


                            //  System.out.println("Date Filtered by Date" + dataFilteredByTerm);
                            YAxis leftAxis = chart.getAxisRight();
                            leftAxis.setEnabled(false);
                            //chart.setBorderColor(Color.RED);


                            chart.setData(new LineData(testDataSet1));
                            chart.getXAxis().setValueFormatter(new IndexAxisValueFormatter(Labels));
                            chart.notifyDataSetChanged();
                            chart.invalidate();

需要图片

获取图片

推荐答案

我自己解决了一个简单的问题,并完成了操作.

I have Solved it myself just a simple twik and its done.

只需添加此内置方法,输出效果就很棒

Just added this inbuilt method and output seems amazing

   setS.setColors(getColorRandom());
                                setS.setDrawFilled(true);
                                setS.setFillColor(getColorRandom());

图片

这篇关于将特定颜色设置为LineChart占用的区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-30 21:04