MPAndroidChart icon indicating copy to clipboard operation
MPAndroidChart copied to clipboard

LineChart can not fully display

Open allenhjf opened this issue 10 years ago • 10 comments

qq 20160914154020

allenhjf avatar Sep 14 '16 07:09 allenhjf

I found the debugging filled data is correct, but is not completely rendering

allenhjf avatar Sep 14 '16 07:09 allenhjf

Hi,

I aggre with @allenhjf .

Every LineChart breaks after the second corner to the top.

I used the debugger to ensure that the XY serie was consistent and it was OK

linechart-1 linechart-2

MirkoAgrati avatar Sep 18 '16 08:09 MirkoAgrati

@MirkoAgrati Could you post the data you used to produce the error shown above + your chart setup?

PhilJay avatar Sep 18 '16 08:09 PhilJay

Hi @PhilJay

I've create a new test LineChart for repeating the scenario since the above images were taken from my device.

Here the setup of the chart

`

 LineChart historyChart = (LineChart) dialog.findViewById(R.id.storyHistoryChart);
 List<Entry> historyChartEntries = StoryChartFactory.getStoryHistoryEntries(story, daysOfTheSprint);

                    //TODO: REMOVE, JUST FOR TEST
                    String tXY = "[";
                    int count = 0;
                    for(Entry e : historyChartEntries){
                        if(count > 0)
                            tXY += ",";

                        tXY += "{X: " + e.getX() + ", Y: " + e.getY() + "}";

                        count++;
                    }
                    tXY += "]";
                    Log.d(LOG_TAG_VALUE, "chart dataset: " + tXY);
                    // -- END TODO

                    LineDataSet dataSet = new LineDataSet(historyChartEntries, "Label"); // add entries to dataset
                    final String colorRes = R.color.colorPrimaryDark + "";
                    dataSet.setColor(Color.parseColor(ctx.getString(Integer.parseInt(colorRes))));
                    dataSet.setLineWidth(3f);

                    LineData lineData = new LineData(dataSet);
                    lineData.setDrawValues(false);
                    historyChart.setData(lineData);

                    XAxis xAxis = historyChart.getXAxis();
                    xAxis.setDrawGridLines(false);
                    xAxis.setCenterAxisLabels(false);
                    xAxis.setDrawLabels(true);
                    xAxis.setGranularityEnabled(true);
                    xAxis.setGranularity(1f);

                    YAxis yLeftAxis = historyChart.getAxis(YAxis.AxisDependency.LEFT);
                    yLeftAxis.setValueFormatter(new StoryStateXAxisFormatter());
                    yLeftAxis.setGranularityEnabled(true);
                    yLeftAxis.setDrawGridLines(false);
                    yLeftAxis.setGranularity(1f);

                    YAxis yRightAxis = historyChart.getAxis(YAxis.AxisDependency.RIGHT);
                    yRightAxis.setDrawGridLines(false);
                    yRightAxis.setDrawLabels(false);
                    yRightAxis.setAxisLineWidth(0);
                    yRightAxis.setDrawAxisLine(false);

                    historyChart.setDescription(ctx.getString(R.string.scrum_story_details_chart_description_lbl));
                    historyChart.setPinchZoom(true);
                    historyChart.setScaleEnabled(true);
                    historyChart.invalidate(); // refresh

`

StoryStateXAxisFormatter

`

public class StoryStateXAxisFormatter implements AxisValueFormatter {

  @Override
  public String getFormattedValue(float value, AxisBase axis) {

      int i_value = (int) value;
      return StoryChartFactory.mapFloatValueToStoryState(i_value);
  }

  @Override
  public int getDecimalDigits() {
    return 0;
  }
}

`

StoryChartFactory

`

public static String mapFloatValueToStoryState(int value){

    switch (value){
        case 1:
            return IterationItemState.OPEN.getShortValue();

        case 2:
            return IterationItemState.SUSPENDED.getShortValue();

        case 3:
            return IterationItemState.IN_PROGRESS.getShortValue();

        case 4:
            return IterationItemState.DEVELOPMENT_DONE.getShortValue();

        case 5:
            return IterationItemState.IN_TEST.getShortValue();

        case 6:
            return IterationItemState.TESTED.getShortValue();

        case 7:
            return IterationItemState.CLOSED.getShortValue();

        default:
            return "";
    }

}

`

Here the dataset:

[{X: 0.0, Y: 1.0},{X: 1.0, Y: 1.0},{X: 2.0, Y: 1.0},{X: 3.0, Y: 1.0},{X: 3.0, Y: 4.0},{X: 4.0, Y: 4.0},{X: 4.0, Y: 5.0},{X: 5.0, Y: 5.0},{X: 6.0, Y: 5.0},{X: 7.0, Y: 5.0},{X: 8.0, Y: 5.0},{X: 8.0, Y: 6.0}]

new test chart image

linechart-1

MirkoAgrati avatar Sep 18 '16 10:09 MirkoAgrati

Thanks for the data, I could finally reproduce the issue. Working on a fix now!

PhilJay avatar Sep 19 '16 11:09 PhilJay

Great!

Thanks to you too :-)

MirkoAgrati avatar Sep 19 '16 11:09 MirkoAgrati

I am having an issue with rendering line chart data using long types as data. It does not expose all of the data points. Is this a similar issue?

For example, if I change the setData() method in your LineChartTime example to using minutes for the X entry, I end up missing the first 90 or so datapoints:

LineChartTime.java lines 271- 301 (roughly)

    private void setData(int count, float range) {

//        long now = System.currentTimeMillis();
//        long hourMillis = 3600000L;
//
//        ArrayList<Entry> values = new ArrayList<Entry>();
//
//        float from = now - (count / 2) * hourMillis;
//        float to = now + (count / 2) * hourMillis;
//
//        for (float x = from; x < to; x += hourMillis) {
//
//            float y = getRandom(range, 50);
//            values.add(new Entry(x, y)); // add one entry per hour
//        }

        List<Entry> values = new ArrayList<>();
        Random rand = new Random();
        float min = 20f;
        float max = 600f;
        Calendar calendar = Calendar.getInstance();
        int times = 4 * 60;
        calendar.add(Calendar.HOUR, -4);

        for (int i = 1; i <= times; i++) {
            values.add(new Entry(calendar.getTimeInMillis(), rand.nextFloat() * (max - min) + min));
            calendar.add(Calendar.MINUTE, 1);
        }

        // create a dataset and give it a type
        LineDataSet set1 = new LineDataSet(values, "DataSet 1");
...

diggybub avatar Sep 19 '16 18:09 diggybub

Is there any update on a fix for this? Or is there a workaround to show all data points?

nfortenberry avatar Oct 18 '16 19:10 nfortenberry

Does anyone have solution for this bug? I have been working on my project using this chart several months, I have to say it's a nice and powerful chart, everything works perfectly until I load the real measure data during the final test.

So much works done make it difficult to change another chart library, what I need is just a solution to display data completely.

zeng-yh avatar Oct 28 '16 10:10 zeng-yh

any update on this one? I am using 3.0.2 and it seems that this issue is still there.

yangdong avatar Jan 30 '18 08:01 yangdong