5

Hello am using MPAndroiChart for my Android App

I stuck with a requirement where I have to draw a line chart(a single line) with different style. Some part of the line is straight and some part is dotted. Something like this

________...........__________________...______

Is it possible to do in MPAndroidChart?

Philipp Jahoda
  • 50,880
  • 24
  • 180
  • 187
Sandeep Tengale
  • 152
  • 4
  • 13

2 Answers2

11

Yes, call lineDataSet.enableDashedLine(...) Documentation: https://github.com/PhilJay/MPAndroidChart/wiki/DataSet-classes-in-detail

Philipp Jahoda
  • 50,880
  • 24
  • 180
  • 187
  • Thank you Philipp, it is making the whole series as dashed but I want to mix both the normal line and dashed line which I mentioned in the question. In my requirement part of line which is below some limit should be shown in dashed line and remaining as a normal line. I am looking for such option. please let me know if there are any method to achieve it. – Sandeep Tengale Oct 08 '15 at 12:11
  • 1
    Use multiple datasets - one dataset with the dashed lines - one with normal – Philipp Jahoda Oct 08 '15 at 13:53
  • Hello Philipp, I tired doing the method you suggested but end up creating lot of datasets. Is it possible to set the different colours in single line. I mean I want to show red colour in missing values, like blue to available value and red for missing value. Please suggest on this. – Sandeep Tengale Oct 13 '15 at 05:32
  • @PhilippJahoda, It's now 2017 , so any resolution for this question , i am looking for same chat, dashed line and continues line in single chart with single datasets, please suggest can I, i need to display 100 data , First 50 continues line and second 50 data with dashed line. thank you – Mahesh Kavathiya Mar 31 '17 at 12:00
  • Did you find any solution ? I was trying to add multiple datasets, but the problem is with animation, I would like to add step by step animation instead of working in parallel. did you achieve this result? – VLeonovs Jun 07 '19 at 07:54
0

Using multiple datasets is a litte bit annoying. This is an example with only a dotted part into a line but it means a lot of code (and you have to repeat entries in every series to make it a continous line), and if you need a line becoming dotted and not dotted some times it must be very difficult to solve:

 ArrayList<Entry> dataValues2 = new ArrayList<Entry>();
        ArrayList<Entry> dataValues3 = new ArrayList<Entry>();
        ArrayList<Entry> dataValues4 = new ArrayList<Entry>();
        
        dataValues2.add(new Entry(0,12));
        dataValues2.add(new Entry(1,10));
        dataValues2.add(new Entry(2,9));
        dataValues2.add(new Entry(3,10));
        dataValues2.add(new Entry(4,9));

        dataValues3.add(new Entry(4,9));//Dotted lines
       dataValues3.add(new Entry(5,8));
        dataValues3.add(new Entry(6,7));
        dataValues3.add(new Entry(7,6));
        dataValues3.add(new Entry(8,5));
        dataValues3.add(new Entry(9,4));
        dataValues3.add(new Entry(10,3));
        dataValues3.add(new Entry(11,5));
        dataValues3.add(new Entry(12,7));
        dataValues3.add(new Entry(13,8));
        dataValues3.add(new Entry(14,10));

        dataValues4.add(new Entry(14,10));
        dataValues4.add(new Entry(15,12));
        dataValues4.add(new Entry(16,11));
        dataValues4.add(new Entry(17,13));
        dataValues4.add(new Entry(18,11));
        dataValues4.add(new Entry(19,14));

        LineChart mpLinechart;
        mpLinechart=findViewById(R.id.linechart);
    
        LineDataSet lineDataSet2=new LineDataSet(dataValues2,"");
        LineDataSet lineDataSet3=new LineDataSet(dataValues3,"");
        LineDataSet lineDataSet4=new LineDataSet(dataValues4,"");

        lineDataSet3.enableDashedLine(12,10,0);
        lineDataSet2.setLineWidth(3f);
        lineDataSet2.setColor(Color.BLUE);

        lineDataSet3.setLineWidth(3f);
        lineDataSet3.setColor(Color.BLUE);
        
        lineDataSet4.setLineWidth(3f);
        lineDataSet4.setColor(Color.BLUE);
        
        ArrayList<ILineDataSet> dataSets=new ArrayList<>();
        dataSets.add(lineDataSet2);
        dataSets.add(lineDataSet3);
        dataSets.add(lineDataSet4);

        LineData data=new LineData(dataSets);
        mpLinechart.setData(data);

        mpLinechart.invalidate();

Graph with dotted lines

jlsogorb
  • 45
  • 1
  • 5