【问题标题】:DateTime axis in MPAndroidChartMPAndroidChart 中的日期时间轴
【发布时间】:2015-09-06 21:56:00
【问题描述】:

我在我的应用程序中使用 MPAndroidChart。我想使用 yAxis 上的值和 xAxis 上的日期来绘制图表。我在 MPAndroidChart API 中没有找到任何日期时间轴。有没有办法使用日期绘制 xAxis?我有根据日期绘制的值。我想在 xAxis 上以 (ddMMM-yy) 格式显示日期,在 yAxis 上显示值。任何人都可以将相同的示例链接传递给我吗?

样本数据:

Date(xAxis) | Value(yAxis)
------------|-------------
01/01/2001  |  966.78
01/02/2001  |  666.78
01/03/2001  |  966.78
01/04/2001  |  966.78
01/05/2001  |  966.78
01/06/2001  |  966.78
01/07/2001  |  966.78

【问题讨论】:

标签: android mpandroidchart


【解决方案1】:

这是最古老的增强功能之一。不幸的是 MPAndroid 还不支持它。 资源: https://github.com/PhilJay/MPAndroidChart/issues/12 https://github.com/PhilJay/MPAndroidChart/issues/133

【讨论】:

  • 看来 2021 年仍然不可能,正如他们所说的那样,解决方案是为每天的条目提供一组索引描述。
【解决方案2】:

我认为您可以根据您的日期调整 Xaxis 数组并将其解析为图表,如

           if (mRecordDate.equals(mCurrentDate)) {
                        float weightVal = 0.0f, bmiValue = 0.0f;
                        try {
                            weightVal = (float) (profileWeightInfo.getWeight());
                        } catch (Exception e) {
                            Log.e("Error" + "Parsing weightVal Entry");
                        }
                        try {
                            bmiValue = (float) (profileWeightInfo.getBmi());
                        } catch (Exception e) {
                            Log.e("Error" + "Parsing diaVal Entry");
                        }
                        valuesWeights.add(new Entry(weightVal, counter));
                        valueBMI.add(new Entry(bmiValue, counter));
                        xVals.add(mRecordDate);

                    }
                }
                if (xVals.indexOf(mCurrentDate) < 0) {
                    valuesWeights.add(new Entry(0, counter));
                    valueBMI.add(new Entry(0, counter));
                    xVals.add(mCurrentDate);
                }
                counter++;

谢谢

【讨论】:

    【解决方案3】:

    我知道现在很晚,但它可能对某人有帮助。

    您可以将日期存储在一个数组中,然后可以使用图表的 setValueFormatter 属性将其显示在图表的 x 轴上。 在顶部声明 dev 数组。 final String dev1[] = new String[100];

    那么你的图表在哪里

       final JSONObject object = jsonArray.getJSONObject(i);
    
       dev1[i] = object.getString("real_time");
       barEntries.add(new BarEntry(i, Float.parseFloat(value)));
       final BarDataSet barDataSetgen = new BarDataSet(barEntries, " ");
    
       XAxis bottomAxis = mcvbarchart.getXAxis();
    
       bottomAxis.setValueFormatter(new IndexAxisValueFormatter(dev1));   /*for x axis values*/
       bottomAxis.setLabelCount(barEntries.size());
       bottomAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    

    【讨论】:

      猜你喜欢
      • 2017-04-09
      • 2017-10-13
      • 2017-05-16
      • 2015-06-08
      • 2021-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多