有人能让这些红线在Highcharts上可拖动吗
尝试使用plotlines时,元素未拖动
- 移动1行时,所有行都应移动
- 如果我选择第一条红线,那么第二条红线也应该移动相同的点。
代码审查:https://jsfiddle.net/gauravjain024/vfq5ybje/11/
enter image description here
var chart = Highcharts.chart('container', {
chart: {
events: {
load() {
var chart = this,
lineWidth = 5;
console.log('chart.xAxis, ', chart.container)
let draggablePlotLine = chart.xAxis[0].plotLinesAndBands[0].svgElem
/* chart.renderer.rect(100, chart.plotTop, lineWidth, chart.plotHeight)
.attr({
fill: 'red'
})
.add(); */
console.log('draggablePlotLine', draggablePlotLine);
//console.log('chart.xAxis[0].plotLinesAndBands[0]', chart.xAxis[0].plotLinesAndBands[0].svgElem)
chart.container.onmousemove = function (e) {
console.log('onmousemove')
if (draggablePlotLine.drag) {
let normalizedEvent = chart.pointer.normalize(e),
extremes = {
left: chart.plotLeft,
right: chart.plotLeft + chart.plotWidth
};
// Move line
if (
e.chartX >= extremes.left &&
e.chartX <= extremes.right
) {
//console.log('draggablePlotLine', e.chartX)
//draggablePlotLine.options.value = e.chartX;
draggablePlotLine.attr({
x: e.chartX
})
}
}
}
draggablePlotLine.element.onmousedown = function () {
console.log('onmousemdown')
draggablePlotLine.drag = true
}
draggablePlotLine.element.onmouseup = function () {
draggablePlotLine.drag = false
}
}
}
},
xAxis: {
plotLines: [{
color: "#FF0000",
width: 5,
value: 3,
drag: true,
label: {
text: "this is label"
}
},
{
color: "#FF0000",
width: 5,
value: 5,
label: {
text: "this is label"
}
},
{
color: "#FF0000",
width: 5,
value: 7,
label: {
text: "this is label"
}
}
]
},
series: [{
name: 'Installation',
data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
}],
});
1条答案
按热度按时间nszi6y051#
使用自定义元素而不是创建默认的地块线将更容易和更有效,类似于以下线程:How do I create a draggable plot line in Highcharts?
下面的解决方案增加了响应性,并在拖动时连接线条。
现场演示:https://jsfiddle.net/BlackLabel/o4m7tfds/
**API引用:**https:// www.example.com