简体   繁体   English

MPAndroid Chart 在实时图表中设置 X

[英]MPAndroid Chart set X in a realtime graph

I work for my school project on MPAndroidChart especially a realtime graph, i would like to display Time of the value.我在 MPAndroidChart 上为我的学校项目工作,尤其是实时图表,我想显示值的时间。

I set a IndexAxisValueFormatter with a "getFormattedValue", it work but refresh every label and not just the last, I try to have for each entry in my graph a XLabel who show the time, I really don't know how to do that you're help would be welcome.我设置了一个带有“getFormattedValue”的 IndexAxisValueFormatter,它可以工作,但每 label 刷新一次,而不仅仅是最后一次,我尝试为图表中的每个条目设置一个显示时间的 XLabel,我真的不知道该怎么做你'欢迎提供帮助。

Code for create an entry and display it:创建条目并显示它的代码:

void creaGraph() {
    ArrayList<ILineDataSet> dataSets = new ArrayList<>();
    if (boxCO2.isChecked()) {
        A_CO2.add(new Entry(indice, listData.recup_data(indice - 1).getCO2()));
        LineDataSet setCO2 = new LineDataSet(A_CO2, "CO2");
        setCO2.setAxisDependency(YAxis.AxisDependency.LEFT);
        paramSet(setCO2);

        setCO2.setColor(Color.RED);
        setCO2.setCircleColor(Color.RED);
        dataSets.add(setCO2);
    }

    LineData data = new LineData(dataSets);
    graph.setData(data);
    data.notifyDataChanged();
    graph.notifyDataSetChanged();
    graph.invalidate();

}

The override of getFormattedValue覆盖 getFormattedValue


@Override
  public String getFormattedValue(float value) {
      return listData.recup_data(GraphPage.indice - 1).getTemps();

  }

And a picture of my issue Every label are refresh when a new entry come和我的问题的图片每个 label 都会在新条目出现时刷新

Also, I see after the 7th values entry no longer have a time values另外,我看到在第 7 个值条目之后不再有时间值

You never use value in getFormattedValue .您永远不会在getFormattedValue中使用value The string you construct there should be based on value or it will show the same thing for every axis entry.您在那里构造的字符串应该基于value ,否则它将为每个轴条目显示相同的内容。

Something like this:是这样的:

@Override
public String getFormattedValue(float value) {
   return makeDateStringAt(value);
}

For example, if you have a chart with axis values at 0, 1, 2, 3 then getFormattedValue will be called 4 times with 0f , 1f , 1f , and 3f as its arguments and you should use those inputs to create the appropriate string to show at those positions on the axis.例如,如果您有一个轴值为 0、1、2、3 的图表,那么getFormattedValue将被调用 4 次,其中0f1f1f3f作为其 arguments 并且您应该使用这些输入来创建适当的字符串以显示在轴上的那些位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM