MPAndroidChart icon indicating copy to clipboard operation
MPAndroidChart copied to clipboard

Cubic line chart

Open Malcom100 opened this issue 9 years ago • 11 comments

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 ?

Malcom100 avatar Dec 26 '16 10:12 Malcom100

@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?

ifeomaro avatar Dec 26 '16 14:12 ifeomaro


    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

Malcom100 avatar Dec 26 '16 15:12 Malcom100

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 !

TSG9876 avatar Dec 27 '16 02:12 TSG9876

I guess you do not have any solutions

Malcom100 avatar Dec 27 '16 08:12 Malcom100

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

JStav avatar Dec 27 '16 18:12 JStav

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

TSG9876 avatar Dec 28 '16 07:12 TSG9876

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

Malcom100 avatar Dec 28 '16 09:12 Malcom100

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

Malcom100 avatar Dec 28 '16 09:12 Malcom100

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

TSG9876 avatar Dec 29 '16 00:12 TSG9876

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.

Edonfreiner avatar Jul 16 '17 02:07 Edonfreiner

I am an avid developer new to android. I want to draw a cubic Bézier curve. i am designing a profile screen i thought it would be nice behind the user's profile photo. what can i do about it. Screenshot from 2022-12-23 11-18-47

yakupcann5 avatar Dec 23 '22 08:12 yakupcann5