Created
May 3, 2018 08:37
-
-
Save ali-master/9138f02dfdf29d8d5875e7a3d2d88ad5 to your computer and use it in GitHub Desktop.
Show crosses for missing values in highcharts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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