chartist icon indicating copy to clipboard operation
chartist copied to clipboard

Adding range markers on donut chart

Open dcorrea80 opened this issue 10 years ago • 4 comments

Hello,

Thank you for all the work you've put in the library, I've enjoyed working with it! I've been working on this issue for a couple of days now and haven't been able to figure it out: Would it be possible to overlay 2 or more markers to indicate a range on a donut chart?

This is what I'm trying to achieve: range_markers

So far, I've tried adding content via an overlay svg and try to absolutely position that on top the chart. I would eventually pass variables (possibly with just a % value), however matching the exact location where the markers are placed on the donut chart is quite challenging. Do you have any suggestions on how to implement this?

dcorrea80 avatar Jan 20 '16 17:01 dcorrea80

Hey there. I felt like doing a plugin for that :-) Feel free to use it under WTFPL. If someone finds the time to wrap this into a repository and make a PR to add it to the docs please go ahead!

http://jsbin.com/huroho/edit?js,output

gionkunz avatar Jan 23 '16 20:01 gionkunz

Thank you so much for taking the time to write the plugin! I wasn't expecting a full solution, this is great! I really like the fact that it allows for any number of markers, as well as the customization options for marker color and length.

dcorrea80 avatar Jan 24 '16 17:01 dcorrea80

Cool no worries! :-)

gionkunz avatar Jan 24 '16 20:01 gionkunz

@gionkunz I am using your written plugin to draw the pointer in my gauge chart and it displays perfectly! But I'm having trouble updating the pointer when I use the myChart.update() functionality.

I initially have your jsbin setup. Then I try to update the pointers by doing the following but the pointers did not change. Is there something I'm missing?

chart.update(sameData, {
      donut: true,
      donutWidth: 150,
      startAngle: 270,
      total: 200,
      plugins: [
        ctDonutMarks({
          marks: [80],
          lineAttributes: {
            stroke: 'red',
          }
        }),
        ctDonutMarks({
          marks: [50],
          lineAttributes: {
            stroke: 'blue',
          }
        })
      ]
    });

sophie-li avatar Feb 06 '17 01:02 sophie-li