android - MPAndroidChart - Round edged bar chart -


i trying create chart below, android application using mpandroidchart. unable figure out, how make bar chart's edges round edged. comes square edge.

enter image description here

so can please suggest me should do?

in advance help.

i've implemented solution achieve straight on library itself.

firstly create attrs.xml adding new attribute use on chart view. this:

<?xml version="1.0" encoding="utf-8"?> <resources>     <declare-styleable name="barchart">         <attr name="radius" format="integer" />     </declare-styleable> </resources> 

then edit method called drawdataset on barchartrenderer:

protected void drawdataset(canvas c, bardataset dataset, int index) {      transformer trans = mchart.gettransformer(dataset.getaxisdependency());      mshadowpaint.setcolor(dataset.getbarshadowcolor());      float phasex = manimator.getphasex();     float phasey = manimator.getphasey();      list<barentry> entries = dataset.getyvals();      // initialize buffer     barbuffer buffer = mbarbuffers[index];     buffer.setphases(phasex, phasey);     buffer.setbarspace(dataset.getbarspace());     buffer.setdataset(index);     buffer.setinverted(mchart.isinverted(dataset.getaxisdependency()));      buffer.feed(entries);      trans.pointvaluestopixel(buffer.buffer);      // if multiple colors     if (dataset.getcolors().size() > 1) {          (int j = 0; j < buffer.size(); j += 4) {              if (!mviewporthandler.isinboundsleft(buffer.buffer[j + 2]))                 continue;              if (!mviewporthandler.isinboundsright(buffer.buffer[j]))                 break;              if (mchart.isdrawbarshadowenabled()) {                 if (mradius > 0)                     c.drawroundrect(new rectf(buffer.buffer[j], mviewporthandler.contenttop(),                             buffer.buffer[j + 2],                             mviewporthandler.contentbottom()), mradius, mradius, mshadowpaint);                 else                     c.drawrect(buffer.buffer[j], mviewporthandler.contenttop(),                             buffer.buffer[j + 2],                             mviewporthandler.contentbottom(), mshadowpaint);             }              // set color drawn value. if index             //             // out of bounds, reuse colors.             mrenderpaint.setcolor(dataset.getcolor(j / 4));             if (mradius > 0)                 c.drawroundrect(new rectf(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2],                         buffer.buffer[j + 3]), mradius, mradius, mrenderpaint);             else                 c.drawrect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2],                         buffer.buffer[j + 3], mrenderpaint);         }     } else {          mrenderpaint.setcolor(dataset.getcolor());          (int j = 0; j < buffer.size(); j += 4) {              if (!mviewporthandler.isinboundsleft(buffer.buffer[j + 2]))                 continue;              if (!mviewporthandler.isinboundsright(buffer.buffer[j]))                 break;              if (mchart.isdrawbarshadowenabled()) {                 if (mradius > 0)                     c.drawroundrect(new rectf(buffer.buffer[j], mviewporthandler.contenttop(),                             buffer.buffer[j + 2],                             mviewporthandler.contentbottom()), mradius, mradius, mshadowpaint);                 else                     c.drawrect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2],                             buffer.buffer[j + 3], mrenderpaint);             }              if (mradius > 0)                 c.drawroundrect(new rectf(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2],                         buffer.buffer[j + 3]), mradius, mradius, mrenderpaint);             else                 c.drawrect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2],                         buffer.buffer[j + 3], mrenderpaint);         }     } } 

by doing you're changing rectangle not highlight, change bit of code on drawhighlighted method:

if (mradius > 0)       c.drawroundrect(mbarrect, mradius, mradius, mhighlightpaint); else       c.drawrect(mbarrect, mhighlightpaint); 

to attribute xml file onto render need add set method well:

public void setradius (int radius) {         mradius = radius; } 

finally create new constructor on barchart object grab radius attribute:

public barchart(context context, attributeset attrs) {         super(context, attrs);         mradius = attrs.getattributeintvalue("http://schemas.android.com/apk/res-auto", "radius", 0);         ((barchartrenderer)mrenderer).setradius(mradius);     } 

and voila! happy coding :)


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -