gpt4 book ai didi

jqPlot - 跨多个图表同步光标

转载 作者:行者123 更新时间:2023-12-04 05:45:01 27 4
gpt4 key购买 nike

我想使用 jqPlot 在页面上创建 3 个单独的图表,是否可以配置 jqPlot 以便当光标在一个图表上移动时,垂直线也会在其他图表上移动?

最佳答案

我还需要同时跟踪 2 个图表上的一条垂直线,并使用 Boro 的答案作为起点,this是我想出的:

var mydata1 = [
[0, 3],
[1, 7],
[2, 9],
[3, 1],
[4, 4],
[5, 6],
[6, 8],
[7, 2],
[8, 5]
];
var mydata2 = [
[0, 5],
[1, 4],
[2, 8],
[3, 7],
[4, 2],
[5, 8],
[6, 5],
[7, 1],
[8, 3]
];
$(document).ready(function () {
var plot1 = $.jqplot(
'chart1', [mydata1], {
seriesDefaults: {
showMarker: false
},
cursor: {
show: true,
showTooltip: false,
showVerticalLine: true,
showHorizontalLine: false
},
highlighter: {
show: true,
showTooltip: false
},
canvasOverlay: {
show: true,
objects: [{
verticalLine: {
show: false,
name: "vline1",
xOffset: '-1',
yOffset: '0',
xaxis: "xaxis",
lineWidth: '0.5',
shadow: false
}
}]
}
});
var plot2 = $.jqplot(
'chart2', [mydata2], {
seriesDefaults: {
showMarker: false
},
cursor: {
show: true,
showTooltip: false,
showVerticalLine: true,
showHorizontalLine: false
},
highlighter: {
show: true,
showTooltip: false
},
canvasOverlay: {
show: true,
objects: [{
verticalLine: {
show: false,
name: "vline2",
xOffset: '-1',
yOffset: '0',
xaxis: "xaxis",
lineWidth: '0.5',
shadow: false
}
}]
}
});

var co1 = plot1.plugins.canvasOverlay;
var co2 = plot2.plugins.canvasOverlay;
var line1 = co1.get('vline1');
var line2 = co2.get('vline2');

$("#chart1").bind('jqplotMouseMove', function (ev, gridpos, datapos, neighbor, data) {
line2.options.show = true;
line2.options.x = datapos.xaxis;
co2.draw(plot2);
});

$("#chart2").bind('jqplotMouseMove', function (ev, gridpos, datapos, neighbor, data) {
line1.options.show = true;
line1.options.x = datapos.xaxis;
co1.draw(plot1);
});

$("#chart1").bind('jqplotMouseLeave', function () {
line2.options.show = false;
co2.draw(plot2);
});

$("#chart2").bind('jqplotMouseLeave', function () {
line1.options.show = false;
co1.draw(plot1);
});
});

Here's the demo

关于jqPlot - 跨多个图表同步光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10783228/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com