Highcharts Dynamic CSS
by Torstein Hønsi
HTML
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="container"></div>
CSS
#container {
min-width: 300px;
max-width: 800px;
height: 300px;
margin: 1em auto;
}
path.high {
fill: yellow;
stroke: red;
stroke-width: 1;
}
JavaScript
Highcharts.wrap(Highcharts.Series.prototype, 'drawPoints', function (proceed) {
proceed.call(this);
$.each(this.points, function () {
if (this.cls && this.graphic) {
this.graphic.addClass(this.cls);
}
});
});
$('#container').highcharts({
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
data: $.map([29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4], function (val) {
return val > 100 ? {
y: val,
cls: 'high'
} : {
y: val,
cls: 'low'
};
})
}]
});