MPAndroidChart icon indicating copy to clipboard operation
MPAndroidChart copied to clipboard

CombinedChart is not work after use chart.clear(). Help me Lord!

Open amsterly opened this issue 9 years ago • 0 comments

1.How to clear chart? I use clearValues(),but nothing changed.The graph is still there.then I use chart.clear(),ok,Chart is reset.Nothing added when I add line again. Here is my code in the lastest version v3.0.1.

private void addNewLine() {
    if (mChart.getData() == null) {
        CombinedData combinedData = new CombinedData();
        if (mChart.getLineData() == null)
            combinedData.setData(new LineData());
        mChart.setData(combinedData);
    }
    mChart.getLineData().addDataSet(generateLineData().getDataSetByIndex(0));
    mChart.notifyDataSetChanged(); // let the chart know it's data changed
    mChart.invalidate(); // refresh
}
private LineData generateLineData() {
    LineData d = new LineData();
    ArrayList<Entry> entries = new ArrayList<Entry>();
    for (int index = 0; index < itemcount; index++)
        entries.add(new Entry(index + 0.5f, random.nextInt(100)));
    LineDataSet set = new LineDataSet(entries, "Line DataSet");
    set.setColor(Color.rgb(240, 238, 70));
    set.setLineWidth(2.5f);
    set.setCircleColor(Color.rgb(240, 238, 70));
    set.setCircleRadius(5f);
    set.setFillColor(Color.rgb(240, 238, 70));
    set.setMode(LineDataSet.Mode.CUBIC_BEZIER);
    set.setDrawValues(true);
    set.setValueTextSize(10f);
    set.setValueTextColor(Color.rgb(240, 238, 70));
    set.setAxisDependency(YAxis.AxisDependency.LEFT);
    d.addDataSet(set);
    return d;
}

amsterly avatar Dec 16 '16 07:12 amsterly