Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradients on Flot

How can I set gradient effects on pie charts?

[{
label: i, 
data: 1000,
color: [ "rgb(190,110,110)", "rgb(140, 70, 70)", "rgb(110, 50, 50)", "rgb(60, 10, 10)" ]
},
//nextserie
]

doesn't work.

Also how can I set gradient effects as default colors for my charts? In the way you can index it by number like:

[{
label: i, 
data: 1000,
color: 1,
},
//nextserie
]
like image 901
Hoffmann Avatar asked Oct 11 '12 16:10

Hoffmann


Video Answer


1 Answers

I have now added support for rendering pie chart with gradients, either radial or linear. My commit is referenced in pull request #853.

An example "default" pie chart with a radial gradient:

$.plot($("#default_gradient"), data, {
    series: {
      pie: {
        show: true,
        gradient: {
          radial: true,
          colors: [
            {opacity: 0.5},
            {opacity: 1.0}
          ]
        }
      }
    }
});

A simple pie chart with a radial gradient

An example donut chart with a radial gradient:

$.plot($("#donut_gradient"), data,
  {
    series: {
      pie: {
        innerRadius: 0.5,
        show: true,
        gradient: {
          radial: true,
          colors: [
            {opacity: 1.0},
            {opacity: 1.0},
            {opacity: 1.0},
            {opacity: 0.5},
            {opacity: 1.0}
          ]
        }
      }
    }
});

A donut chart with a radial gradient

An example of a tilted pie chart with a radial gradient:

  $.plot($("#graph9_gradient"), data,
  {
    series: {
      pie: {
        show: true,
        radius: 1,
        tilt: 0.5,
        gradient: {
          radial: true,
          colors: [
            {opacity: 0.5},
            {opacity: 1.0}
          ]
        },
        label: {
          show: true,
          radius: 1,
          formatter: function(label, series){
            return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';
          },
          background: { opacity: 0.8 }
        },
        combine: {
          color: '#999',
          threshold: 0.1
        }
      }
    },
    legend: {
      show: false
    }
  });

A tilted pie chart with a radial gradient

The changes were based on a combination of the above suggestions proposed by @Hoffman and a patch suggested in Flot issue #355 by Luc Boudreau.

like image 67
Martin Thorsen Ranang Avatar answered Oct 16 '22 01:10

Martin Thorsen Ranang