Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ali-master/9138f02dfdf29d8d5875e7a3d2d88ad5 to your computer and use it in GitHub Desktop.
Save ali-master/9138f02dfdf29d8d5875e7a3d2d88ad5 to your computer and use it in GitHub Desktop.
Show crosses for missing values in highcharts
/**
* Highcharts plugin to draw crosses for null points
*/
(function(H) {
H.wrap(H.Series.prototype, "drawPoints", function(proceed) {
var series = this,
points = this.points,
renderer = this.chart.renderer;
proceed.call(this);
H.each(points, function(point, i) {
var lastPlotY,
lastI = i - 1,
nextPlotY,
nextI = i + 1,
plotY;
if (point.y === null) {
while (lastI >= 0 && lastPlotY === undefined) {
lastPlotY = points[lastI].plotY;
lastI--;
}
while (nextI <= points.length - 1 && nextPlotY === undefined) {
nextPlotY = points[nextI].plotY;
nextI++;
}
// Interpolate
plotY = (H.pick(lastPlotY, nextPlotY) + H.pick(nextPlotY, lastPlotY)) / 2;
var path = ["M", point.plotX - 3, plotY - 3, "L", point.plotX + 3, plotY + 3, "M", point.plotX - 3, plotY + 3, "L", point.plotX + 3, plotY - 3];
if (point.graphic) {
point.graphic.attr({
d: path,
});
} else {
point.graphic = renderer
.path(path)
.attr({
stroke: "red",
"stroke-width": 1,
fill: "none",
})
.add(series.markerGroup);
}
}
});
});
})(Highcharts);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment