javascript - Add text to generated quadrant area by x and y plot lines , highcharts -
i have scatter chart demonstrate load servers 2 dimensions , x , y.
and define 2 plot lines show if point overload, demo shows(just quick demo , copy link):
"http://codepen.io/anon/pen/xzprwa"
while, need demonstrate generated quadrant means labels like:
but can't find methods/options api achieve this, there simple method this? find position , put label absolute position?
you can define plotlines per x , y axis , catch load event. inside function, should extract position of lines , use renderer print labels. last step calculate osition proper quarter (by comparing plotlines , checking width of label - getbbox - function).
chart: { events: { load: function() { var chart = this, r = chart.renderer, each = highcharts.each, left = chart.plotleft, top = chart.plottop, h = chart.plotheight, w = chart.plotwidth, xaxis = chart.xaxis[0], yaxis = chart.yaxis[0], labels = ['top-left', 'top-right', 'bottom-left', 'bottom-right'], labelstyles = { 'font-size': '12px', 'color': 'red' }, attr = { zindex: 10 }, xplotline, yplotline,bbox, x, y; chart.label = []; xplotline = xaxis.topixels(xaxis.plotlinesandbands[0].options.value); yplotline = yaxis.topixels(yaxis.plotlinesandbands[0].options.value); //render each(labels, function(label, i) { chart.label[i] = r.text(label, 0, 0) .attr(attr) .css(labelstyles) .add(); bbox = chart.label[i].getbbox(); console.log(w); switch(i) { case 0: x = ((xplotline + left) / 2) - (bbox.width / 2); y = ((yplotline + top) / 2) - (bbox.height / 2); break; case 1: x = left + xplotline + ((w - xplotline)/2) - (bbox.width / 2); y = ((yplotline + top) / 2) - (bbox.height / 2); break; case 2: x = ((xplotline + left) / 2) - (bbox.width / 2); y = top + yplotline + ((h - yplotline) / 2) - (bbox.height / 2); break; case 3: x = left + xplotline + ((w - xplotline)/2) - (bbox.width / 2); y = top + yplotline + ((h - yplotline) / 2) - (bbox.height / 2); break; } chart.label[i].attr({ x: x, y: y }); }); } } }, xaxis: { plotlines: [{ id: 'ver', color: '#ff0000', width: 2, value: 2 }] }, yaxis: { plotlines: [{ id: 'hor', color: '#ff0000', width: 2, value: 100 }] },
example: http://jsfiddle.net/x1zna57a/
Comments
Post a Comment