【问题标题】:MPAndroidchart - Candlestick chart is blankMPAndroidchart - 烛台图为空白
【发布时间】:2017-05-30 01:04:40
【问题描述】:

正如标题所说,我正在尝试将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, 2.70f, 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();

但我明白了:

图表 XML

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

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

【问题讨论】:

  • 请包含您正在使用图表的应用程序部分的 XML。也许您正在为图表使用背景颜色 (android:background="")?如果是,请不要。
  • 已编辑以包含图表 Xml。我没有设置背景。

标签: android mpandroidchart


【解决方案1】:

我认为你的 x 轴必须使用低于 1000 的值我不知道为什么,但是当我尝试这个解决方案时,我的图表就像一个魅力 如果您想为 x 轴添加时间,可以将时间戳除以 1000000000.0,然后在值格式化程序中将此值与您的值交叉。

【讨论】:

    【解决方案2】:

    尝试用以下代码替换您的代码。

    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, 2.70f, 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.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();
    

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

    【讨论】:

    • 成功!谢谢!
    猜你喜欢
    • 2015-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-09
    • 2013-12-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多