MPAndroidchart – 烛台图表为空白

正如标题所说,我试图将 MPAndroidChart包含在一个项目中,并且不能让蜡烛显示出来.这是我的代码

List<CandleEntry> ceList = new ArrayList<>();
    ceList.add(new CandleEntry(0,4.62f,2.02f,2.70f,4.13f));
    ceList.add(new CandleEntry(1,5.50f,3.35f,4.96f));
    ceList.add(new CandleEntry(2,5.25f,3.02f,3.50f,4.50f));
    ceList.add(new CandleEntry(3,6f,3.25f,4.40f,5.0f));
    ceList.add(new CandleEntry(4,5.57f,2f,2.80f,4.5f));
    CandleDataSet cds = new CandleDataSet(ceList,"Entries");
    cds.setColor(Color.BLUE);
    cds.setValueTextColor(Color.RED);
    CandleData cd = new CandleData(cds);
    candleStickChart.setData(cd);
    candleStickChart.invalidate();

但我明白了:

enter image description here

图表Xml

<com.github.mikephil.charting.charts.CandleStickChart
    android:id="@+id/CandleStickChart"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

带有折线图的相同代码似乎工作正常.
我有什么想法可能做错了吗?
谢谢!

解决方法

尝试使用以下代码替换您的代码.

List<CandleEntry> ceList = new ArrayList<>();
    ceList.add(new CandleEntry(0,4.5f));


    CandleDataSet cds = new CandleDataSet(ceList,"Entries");
    cds.setColor(Color.rgb(80,80,80));
    cds.setShadowColor(Color.DKGRAY);
    cds.setShadowWidth(0.7f);
    cds.setDecreasingColor(Color.RED);
    cds.setDecreasingPaintStyle(Paint.Style.FILL);
    cds.setIncreasingColor(Color.rgb(122,242,84));
    cds.setIncreasingPaintStyle(Paint.Style.stroke);
    cds.setNeutralColor(Color.BLUE);
    cds.setValueTextColor(Color.RED);
    CandleData cd = new CandleData(cds);
    candleStickChart.setData(cd);
    candleStickChart.invalidate();

在此,您必须指定某些属性.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...