如何使用一个整数ArrayList设置MPAndroidChart折线图(LineChart)的数据?

huangapple go评论67阅读模式
英文:

How to set data of MPAndroidChart LineChart with an ArrayList of Ints?

问题

我有一个整数ArrayList,我想在我的MPAndroidChart LineChart中使用它。然而,我对Java还很陌生,不知道如何将其转换为所需的"Entry"数据类型。你能帮助我吗?

我尝试了以下方法:

ArrayList<int[]> data2line = new ArrayList<>(Arrays.asList(data));

LineDataSet lineDataSet1 = new LineDataSet(data2line, "数据集1");
ArrayList<ILineDataSet> dataSets = new ArrayList<>();
dataSets.add(lineDataSet1);

LineData dataLine = new LineData(dataSets);
lineChart.setData(dataLine);
英文:

I have an ArrayList of ints that I would like to use in my MPAndroidChart LineChart. However, I am new to Java and don't know how to convert it to the required "Entry" data type. Can you help me?

I tried the following:

ArrayList&lt;int[]&gt; data2line= new ArrayList&lt;&gt;(Arrays.asList(data));

LineDataSet lineDataSet1 = new LineDataSet(data2line,&quot;Data Set 1&quot;);
ArrayList&lt;ILineDataSet&gt; dataSets = new ArrayList&lt;&gt;();
dataSets.add(lineDataSet1);

LineData dataLine = new LineData(dataSets);
lineChart.setData(dataLine);

答案1

得分: 0

ArrayList entries = new ArrayList<>();
entries.add(new Entry(1, 50));
entries.add(new Entry(2, 100));

英文:

You need an array of entries, something like this:

ArrayList&lt;Entry&gt; entries = new ArrayList&lt;&gt;();
entries.add(new Entry(1, 50));
entries.add(new Entry(2, 100));

huangapple
  • 本文由 发表于 2020年9月13日 20:59:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/63871068.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定