【问题标题】:How to add real time data in Barchart using MPAndroidChart library如何使用 MPAndroidChart 库在 Barchart 中添加实时数据
【发布时间】:2017-01-30 13:13:44
【问题描述】:

我正在使用 MPAndroid 图表库来绘制 BarChart。 但没有得到如何在按钮点击时使用实时数据绘制条形图。 任何人都可以在这方面帮助我。 谢谢。

【问题讨论】:

  • 对不起,这真的不清楚。 “实时数据”到底是什么意思?您的意思是“添加到数据集”吗?
  • 您已经问过这个问题here 并且它已关闭。花一些时间明确您的问题,我们会尽力帮助您

标签: android bar-chart mpandroidchart


【解决方案1】:

在获取数据后将其存储在 List(graphData) 中。那么,

BarChart barChart;
/*List to store real time data*/
private List<Integer> graphData = new ArrayList<>();

/*List of String which contains X-axis values */
ArrayList<String> xAxisValuesList = new ArrayList<>();

// create BarEntry for group     
ArrayList<BarEntry> group = new ArrayList<>();
for (int i = 0; i < graphData.size(); i++) {
    Log.d(TAG, "generating for:" + graphData.get(i));
    group.add(new BarEntry(graphData.get(i), i));
} 

// creating dataset for group
BarDataSet barDataSet = new BarDataSet(group, "Label");

// combined all dataset into an arraylist
ArrayList<BarDataSet> dataSets = new ArrayList<>();  
dataSets.add(barDataSet); 

// initialize the Bardata with argument labels and dataSet
BarData barData = new BarData(xAxisValuesList, dataSets); 
barChart.setData(barData); 

【讨论】:

  • 虽然很高兴能提供帮助,但您应该尝试承认您的来源。看来您是基于此处的教程:numetriclabz.com/… 这可能没关系,因为它不是直接复制/粘贴。如果您包含指向教程的链接,它可能会更好
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-08
  • 2015-05-27
相关资源
最近更新 更多