gwatts / jquery.sparkline

A plugin for the jQuery javascript library to generate small sparkline charts directly in the browser
http://omnipotent.net/jquery.sparkline/
1.24k stars 278 forks source link

Allow colorMap to be expressed as a function(index,value) for bar charts #83

Open andykellr opened 11 years ago

andykellr commented 11 years ago

When you have a large data set and you want to use different colors for different values, expressing the colorMap as a map may be insufficient and an Array isn't very compact. Instead a function should be used.

For example, if 1 is a meaningful threshold for the data, you might want to use:

{type:"bar", colorMap: function(i,val) { return (val > 1) ? "#f00" : "#000"; } }

Or if you want to emphasize the first 5 values:

{type:"bar", colorMap: function(i,val) { return (i < 5) ? "#f00" : "#000"; } }

I'm open to other suggestions for syntax, but this is how I have implemented it in my fork.