无论如何使用MPAndroidChart动态设置值为Yaxis。我搜索了问题,但在这里我没有得到任何答案。我必须将运行时值设置为Yaxis。我也试过setGranularity(),但是这个方法显示的错误像can't resolve method setGranularity(float)
。请帮助我。
答案 0 :(得分:0)
你可以这样尝试
private ArrayList<Entry> setYAxisValues(){
ArrayList<Entry> yVals = new ArrayList<Entry>();
//Change to your values
yVals.add(new Entry(0, 6));
yVals.add(new Entry(1, 4));
yVals.add(new Entry(2, 5));
yVals.add(new Entry(3, 4));
yVals.add(new Entry(4, 3));
yVals.add(new Entry(5, 2));
yVals.add(new Entry(6, 3));
yVals.add(new Entry(7, 4));
yVals.add(new Entry(8, 5));
yVals.add(new Entry(9, 3));
yVals.add(new Entry(10, 2));
yVals.add(new Entry(11,4));
return yVals;
}
private void setData() {
//call this method to set data
ArrayList<Entry> yVals = setYAxisValues();
LineDataSet set1;
// create a dataset and give it a type
set1 = new LineDataSet(yVals, "DataSet 1");
set1.setFillAlpha(110);
set1.setColor(Color.WHITE);
set1.setCircleColor(Color.WHITE);
set1.setLineWidth(1f);
set1.setCircleRadius(3f);
set1.setDrawCircleHole(false);
set1.setValueTextSize(9f);
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
dataSets.add(set1); // add the datasets
// create a data object with the datasets
LineData data = new LineData(dataSets);
// set data to LineChart
mChart.setData(data);
mChart.setVisibleXRangeMaximum(4); // allow 20 values to be displayed at once on the x-axis, not more
mChart.moveViewToX(10);
}