Mpandroidchart: Cubic line chart

Created on 26 Dec 2016  路  10Comments  路  Source: PhilJay/MPAndroidChart

Hi,
This is the first time that I use the MPAndroidchart librairy, the 3.0.1 version ia used.
I have a little problem with my line chart, the curve is not well drawn
This is my config :
lineDataSetEvent.setMode(LineDataSet.Mode.CUBIC_BEZIER); lineDataSetEvent.setColor(Constants.colors.get(k)); lineDataSetEvent.setDrawValues(false); lineDataSetEvent.setDrawCircles(false);

image

What is I do bad in my config ?
Did I forget something ?

Most helpful comment

Instead of CUBIC_BEZIER, try using HORIZONTAL_BEZIER and see if that works any better. I had all sorts of problems with CUBIC_BEZIER.

All 10 comments

@Malcom100 Could you include the entire setup code you used to generate the chart above and also the chart you expect to generate with the library?

    dataSets = new ArrayList<ILineDataSet>();
        for(Map.Entry<String,List<ValuesAxis>> v : channelsMap.entrySet()) 
            String key = v.getKey();
            List<ValuesAxis> values = v.getValue();
            List<Entry> entries = new ArrayList<Entry>();
            for(ValuesAxis value : values){
                float x = value.getTime().floatValue();
                float y = (float) value.getValue();
                entries.add(new Entry(x,y));
            String nameLabel;
            if(labelsName != null && labelsName.containsKey(key)){
                nameLabel = labelsName.get(key);
            }
            LineDataSet lineDataSet = new LineDataSet(entries,nameLabel);
            lineDataSet.setColor(Constants.colors.get(i));
            lineDataSet.setDrawValues(false);
            lineDataSet.setDrawCircles(false);
            lineDataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
            lineDataSet.setCubicIntensity(0.2f);
            dataSets.add(lineDataSet);
        }

        lineChart.setData(dataSet);
        lineChart.getAxisRight().setEnabled(false);
        lineChart.getDescription().setEnabled(false);
        lineChart.setDrawMarkerViews(true);
        CustomMarkerView customMarkerView = new CustomMarkerView(context,R.layout.layout_marker_view,canMoveX ? "r" : scale);
        lineChart.setMarkerView(customMarkerView);
        Legend legend = lineChart.getLegend();
        legend.setPosition(Legend.LegendPosition.BELOW_CHART_LEFT);
        legend.setXEntrySpace(7f);
        legend.setYEntrySpace(0f);
        legend.setYOffset(0);
        legend.setWordWrapEnabled(true);

        XAxis xAxis = lineChart.getXAxis();
        xAxis.setValueFormatter(new MyXAxisValueFormatter(canMoveX ? "r" : scale));
        xAxis.setPosition(XAxis.XAxisPosition.TOP);
        xAxis.setTextSize(8);
        xAxis.setLabelCount(8);
        xAxis.setDrawGridLines(false);
        lineChart.setScaleMinima(1,1);
        lineChart.invalidate();

I woul like have a cubic line chart like this :
image

I have the same issue with the cubic line chart even if if I set it to Max lineDataSet.setCubicIntensity(1.0f), cubic line just could not have the smooth curvature !

I guess you do not have any solutions

Instead of CUBIC_BEZIER, try using HORIZONTAL_BEZIER and see if that works any better. I had all sorts of problems with CUBIC_BEZIER.

Why your times series x-axis valueformatter look so erratic at 5 minutes gap against the input voltage plot , is your input continuously feeding data into into chart to be graphed ? I suggest you have a look at the real-time chart example to see how to feed new data non-stop into the chart

I replace CUBIC_BEZIER by HORIZENTAL_BEZIER and this is better thanks @JStav.

@TSG9876 where can I find this example, in the Github project ?

I tested my continuous data feed with 1second interval using the default setting such as lineDataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
lineDataSet.setCubicIntensity(0.2f); and curve look quite ok now , at max =1.0f becomes too winding end up as polar curve instead.

sample cubic line chart and many other examples could be found at

https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CubicLineChartActivity.java

Hi all, I have the same issue now, I posted it on stack overflow, but no one is seeming to respond. Can anyone please help me?

https://stackoverflow.com/questions/45104391/mpandroidchart-making-curved-graphs

Thank you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

botondbutuza picture botondbutuza  路  3Comments

rohitkumarbhagat picture rohitkumarbhagat  路  3Comments

galex picture galex  路  3Comments

mrZizik picture mrZizik  路  3Comments

Giammaofwar picture Giammaofwar  路  3Comments