JSFiddle - React, Tailwind, and code Playground
by andrei
HTML
<script src="http://code.highcharts.com/highcharts.src.js"></script>
<div id="container" style="height: 400px"></div>
JavaScript
$(function () {
var rectangle;
// create the chart
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
events: {
selection: function (event) {
var mouseDownX = this.mouseDownX,
plotWidth = chart.plotWidth,
chartX = e.chartX;
// If the mouse is outside the plot area, adjust to cooordinates
// inside to prevent the selection marker from going outside
if (chartX < plotLeft) {
chartX = plotLeft;
} else if (chartX > plotLeft + plotWidth) {
chartX = plotLeft + plotWidth;
}
size = chartX - mouseDownX;
this.selectionMarker.attr({
width: mathAbs(size),
x: (size > 0 ? 0 : size) + mouseDownX
});
chart.renderer.rect(plotLeft,
plotTop,
zoomHor ? 1 : plotWidth,
zoomVert ? 1 : plotHeight,
0).attr({
'stroke-width': 2,
stroke: 'red',
fill: 'yellow',
zIndex: 3,
opacity: 0.5
}).add();
return false;
}
},
zoomType: 'x'
},
xAxis: {},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
});
});