【问题标题】:mChart android color not changingmChart android颜色没有改变
【发布时间】:2021-08-04 19:36:30
【问题描述】:

我正在使用 Mphil 图表库,我已为我的折线图添加了此代码。

但它没有改变颜色,它显示默认紫色,我的代码中是否有遗漏或错误

  LineDataSet set1;
        if (mChart.getData() != null &&
                mChart.getData().getDataSetCount() > 0) {
            set1 = (LineDataSet) mChart.getData().getDataSetByIndex(0);
            set1.setValues(values);
            mChart.getData().notifyDataChanged();
            mChart.notifyDataSetChanged();



        } else {
            set1 = new LineDataSet(values, "");
            set1.setDrawIcons(false);
            set1.setLabel("");
            set1.setDrawValues(false);
            set1.setHighLightColor(R.color.extracyan);
            mChart.getLegend().setEnabled(false);
            // set1.enableDashedLine(10f, 5f, 0f);
            //set1.enableDashedHighlightLine(10f, 5f, 0f);
            set1.setColor(R.color.extracyan);
            set1.setCircleColor(R.color.extracyan);
            set1.setLineWidth(3.5f);
            set1.setDrawCircles(false);
            set1.setCircleRadius(3.5f);
            set1.setDrawCircleHole(false);
            set1.setValueTextSize(0f);
            set1.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
            set1.setDrawFilled(false);
            set1.setFormLineWidth(2.5f);
            set1.setFormLineDashEffect(new DashPathEffect(new float[]{10f, 5f}, 0f));
            set1.setFormSize(15.f);

            /*if (Utils.getSDKInt() >= 18) {
                Drawable drawable = ContextCompat.getDrawable(this, R.drawable.fade_blue);
                set1.setFillDrawable(drawable);
            } else {
                set1.setFillColor(R.color.cyan);
            }*/
            ArrayList<ILineDataSet> dataSets = new ArrayList<>();
            dataSets.add(set1);
            LineData data = new LineData(dataSets);
            mChart.setData(data);
            progresslayout.setVisibility(View.GONE);
           txtProgress.setVisibility(View.GONE);

        }

我尝试添加差异颜色,差异方法,但仍然相同,我尝试添加 2 组差异颜色但改变,它们都是相同颜色的

【问题讨论】:

    标签: java android firebase android-studio


    【解决方案1】:

    您可以通过以下方式为您的charts 添加多个 颜色

      ArrayList<Integer> colors = new ArrayList<>();
                for (int c : ColorTemplate.JOYFUL_COLORS)
                    colors.add(c);
                for (int c : ColorTemplate.LIBERTY_COLORS)
                    colors.add(c);
                for (int c : ColorTemplate.COLORFUL_COLORS)
                    colors.add(c);
                for (int c : ColorTemplate.VORDIPLOM_COLORS)
                    colors.add(c);
                for (int c : ColorTemplate.PASTEL_COLORS)
                    colors.add(c);
        set1.setColors(colors);
    

    将此代码替换为set1.setColor(R.color.extracyan);

    【讨论】:

      猜你喜欢
      • 2016-05-12
      • 1970-01-01
      • 1970-01-01
      • 2021-04-08
      • 2015-10-29
      • 2021-10-04
      • 2011-07-31
      • 2021-04-05
      • 1970-01-01
      相关资源
      最近更新 更多