Open mshcheng opened 7 years ago
Hi, are you calling chart.invalidate()
after changing the data set?
Yup i did. Below is the code that i use to draw the chart with. I basically only change the currentEntries arraylist when i switch between dataset A and B.
currentSet = new LineDataSet(currentEntries, "current_carbon");
currentSet.setColor(ContextCompat.getColor(chart.getActivity(), R.color.current_carbon_line));
currentSet.setLineWidth(1f);
currentSet.setCircleColor(ContextCompat.getColor(chart.getActivity(), R.color.current_carbon_line));
currentSet.setCircleRadius(3f);
currentSet.setDrawCircleHole(true);
currentSet.setDrawValues(false);
dataSets.add(currentSet);
LineData lData = new LineData(dataSets);
XAxis xAxis = chart.getXAxis();
xAxis.setValueFormatter(new MealAxisValueFormatter(chart.getActivity(), chart));
xAxis.setGranularity(1f);
xAxis.setLabelRotationAngle(90);
xAxis.setAxisMinValue(0f);
xAxis.setAxisMaxValue((float) (numOfDays*numOfMeals)-1);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setLabelCount(numOfDays*numOfMeals);
chart.getAxisLeft().setAxisMinValue(0f);
chart.getAxisRight().setEnabled(false);
chart.setDrawBorders(true);
chart.clearValues();
chart.setData(lData);
chart.animateX(1000);
chart.invalidate();
chart.fitScreen();
Does it work if you add chart.notifyDataSetChanged()
?
Tried that just now, still the same.
Did work out an answer to this? I am having the same problem, when I redraw with shorter series, so the x axis is reduced in length. Redrawing longer is fine.
I got mine to work by recreating the LineData object rather than just amending the values in the LineDataSet
Hi, I just got that problem, just call calcMinMax() on your dataset to compute again the min and max of axis like that : chart.lineData.dataSets.first().calcMinMax()
And then invalidate() to redraw with new axis' min max
@tamslinn thanks for the suggestion, I got mine to work by doing that as well
anyone found the solution?
Before i ask my question, let me first say that this is the most powerful and feature-rich charting library I have used on the Android platform. The documentation is great, and i can find lots of resources on stackoverflow as well.
But i recently come across one issue that i don't know it is a bug or i just haven't done the right thing. I have setup this chart object to occupy full width of the layout/screen. On the initial draw with dataset A, the chart appears fine, taking up the full width. Note that the left Y-axis labels are fairly long in this case.
When i redraw the chart with different dataset B, with shorter Y-axis labels, the chart doesn't seem to take the full width of the screen (ie. leaving a wide blank space on the left side).
But if at the very start, i select dataset B (without selecting dataset A first), the chart is drawn properly without leaving a wide blank space on the left.
Have i missed something here ? any help is appreciated.