Highcharts redraw and sort data on draggable line graph
I have a line chart in Highcharts and want to redraw or the line when dragging a point past another point.
I want to redraw and sort the chart while dragging so the line updates and don't cross eachother. We can update the chart with chart.series[0].setData() or chart.series[0].update(); but i keep getting sorting errors or errors with the draggable point being null (dragPoint or hoverPoint) when updating the chart
Here is an example where I detect when a point is being dragged past another by changing the getNewPos(e) function in the draggable module
http://jsfiddle.net/u4xpmf2j/1/
*/
function getNewPos(e) {
toClose = false;
var originalEvent = e.originalEvent || e,
pageX = originalEvent.changedTouches ? originalEvent.changedTouches[0].pageX : e.pageX,
pageY = originalEvent.changedTouches ? originalEvent.changedTouches[0].pageY : e.pageY,
series = dragPoint.series,
draggableX = series.options.draggableX && dragPoint.draggableX !== false,
draggableY = series.options.draggableY && dragPoint.draggableY !== false,
dragSensitivity = pick(series.options.dragSensitiviy, 1),
dragMaxToPoint = pick(series.options.dragMaxToPoint, 0.3),
deltaX = draggableX ? dragX - pageX : 0,
deltaY = draggableY ? dragY - pageY : 0,
newPlotX = dragPlotX - deltaX,
newPlotY = dragPlotY - deltaY,
newX = dragX === undefined ? dragPoint.x : series.xAxis.toValue(newPlotX, true),
newY = dragY === undefined ? dragPoint.y : series.yAxis.toValue(newPlotY, true),
ret;
newX = filterRange(newX, series, 'X');
newY = filterRange(newY, series, 'Y');
if (dragPoint.index > 0 && (newX - dragPoint.series.data[dragPoint.index - 1].x) < dragMaxToPoint || dragPoint.index < dragPoint.series.data.length - 1 && (newX - dragPoint.series.data[dragPoint.index + 1].x) > -dragMaxToPoint) {
toClose = true; // DETECT POINT BEING DRAGGED PAST ANOTHER
}
if (Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2)) > dragSensitivity) {
return {
x: draggableX ? newX : dragPoint.x,
y: draggableY ? newY : dragPoint.y
};
} else {
return null;
}
}
Any ideas?
javascript highcharts
add a comment |
I have a line chart in Highcharts and want to redraw or the line when dragging a point past another point.
I want to redraw and sort the chart while dragging so the line updates and don't cross eachother. We can update the chart with chart.series[0].setData() or chart.series[0].update(); but i keep getting sorting errors or errors with the draggable point being null (dragPoint or hoverPoint) when updating the chart
Here is an example where I detect when a point is being dragged past another by changing the getNewPos(e) function in the draggable module
http://jsfiddle.net/u4xpmf2j/1/
*/
function getNewPos(e) {
toClose = false;
var originalEvent = e.originalEvent || e,
pageX = originalEvent.changedTouches ? originalEvent.changedTouches[0].pageX : e.pageX,
pageY = originalEvent.changedTouches ? originalEvent.changedTouches[0].pageY : e.pageY,
series = dragPoint.series,
draggableX = series.options.draggableX && dragPoint.draggableX !== false,
draggableY = series.options.draggableY && dragPoint.draggableY !== false,
dragSensitivity = pick(series.options.dragSensitiviy, 1),
dragMaxToPoint = pick(series.options.dragMaxToPoint, 0.3),
deltaX = draggableX ? dragX - pageX : 0,
deltaY = draggableY ? dragY - pageY : 0,
newPlotX = dragPlotX - deltaX,
newPlotY = dragPlotY - deltaY,
newX = dragX === undefined ? dragPoint.x : series.xAxis.toValue(newPlotX, true),
newY = dragY === undefined ? dragPoint.y : series.yAxis.toValue(newPlotY, true),
ret;
newX = filterRange(newX, series, 'X');
newY = filterRange(newY, series, 'Y');
if (dragPoint.index > 0 && (newX - dragPoint.series.data[dragPoint.index - 1].x) < dragMaxToPoint || dragPoint.index < dragPoint.series.data.length - 1 && (newX - dragPoint.series.data[dragPoint.index + 1].x) > -dragMaxToPoint) {
toClose = true; // DETECT POINT BEING DRAGGED PAST ANOTHER
}
if (Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2)) > dragSensitivity) {
return {
x: draggableX ? newX : dragPoint.x,
y: draggableY ? newY : dragPoint.y
};
} else {
return null;
}
}
Any ideas?
javascript highcharts
add a comment |
I have a line chart in Highcharts and want to redraw or the line when dragging a point past another point.
I want to redraw and sort the chart while dragging so the line updates and don't cross eachother. We can update the chart with chart.series[0].setData() or chart.series[0].update(); but i keep getting sorting errors or errors with the draggable point being null (dragPoint or hoverPoint) when updating the chart
Here is an example where I detect when a point is being dragged past another by changing the getNewPos(e) function in the draggable module
http://jsfiddle.net/u4xpmf2j/1/
*/
function getNewPos(e) {
toClose = false;
var originalEvent = e.originalEvent || e,
pageX = originalEvent.changedTouches ? originalEvent.changedTouches[0].pageX : e.pageX,
pageY = originalEvent.changedTouches ? originalEvent.changedTouches[0].pageY : e.pageY,
series = dragPoint.series,
draggableX = series.options.draggableX && dragPoint.draggableX !== false,
draggableY = series.options.draggableY && dragPoint.draggableY !== false,
dragSensitivity = pick(series.options.dragSensitiviy, 1),
dragMaxToPoint = pick(series.options.dragMaxToPoint, 0.3),
deltaX = draggableX ? dragX - pageX : 0,
deltaY = draggableY ? dragY - pageY : 0,
newPlotX = dragPlotX - deltaX,
newPlotY = dragPlotY - deltaY,
newX = dragX === undefined ? dragPoint.x : series.xAxis.toValue(newPlotX, true),
newY = dragY === undefined ? dragPoint.y : series.yAxis.toValue(newPlotY, true),
ret;
newX = filterRange(newX, series, 'X');
newY = filterRange(newY, series, 'Y');
if (dragPoint.index > 0 && (newX - dragPoint.series.data[dragPoint.index - 1].x) < dragMaxToPoint || dragPoint.index < dragPoint.series.data.length - 1 && (newX - dragPoint.series.data[dragPoint.index + 1].x) > -dragMaxToPoint) {
toClose = true; // DETECT POINT BEING DRAGGED PAST ANOTHER
}
if (Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2)) > dragSensitivity) {
return {
x: draggableX ? newX : dragPoint.x,
y: draggableY ? newY : dragPoint.y
};
} else {
return null;
}
}
Any ideas?
javascript highcharts
I have a line chart in Highcharts and want to redraw or the line when dragging a point past another point.
I want to redraw and sort the chart while dragging so the line updates and don't cross eachother. We can update the chart with chart.series[0].setData() or chart.series[0].update(); but i keep getting sorting errors or errors with the draggable point being null (dragPoint or hoverPoint) when updating the chart
Here is an example where I detect when a point is being dragged past another by changing the getNewPos(e) function in the draggable module
http://jsfiddle.net/u4xpmf2j/1/
*/
function getNewPos(e) {
toClose = false;
var originalEvent = e.originalEvent || e,
pageX = originalEvent.changedTouches ? originalEvent.changedTouches[0].pageX : e.pageX,
pageY = originalEvent.changedTouches ? originalEvent.changedTouches[0].pageY : e.pageY,
series = dragPoint.series,
draggableX = series.options.draggableX && dragPoint.draggableX !== false,
draggableY = series.options.draggableY && dragPoint.draggableY !== false,
dragSensitivity = pick(series.options.dragSensitiviy, 1),
dragMaxToPoint = pick(series.options.dragMaxToPoint, 0.3),
deltaX = draggableX ? dragX - pageX : 0,
deltaY = draggableY ? dragY - pageY : 0,
newPlotX = dragPlotX - deltaX,
newPlotY = dragPlotY - deltaY,
newX = dragX === undefined ? dragPoint.x : series.xAxis.toValue(newPlotX, true),
newY = dragY === undefined ? dragPoint.y : series.yAxis.toValue(newPlotY, true),
ret;
newX = filterRange(newX, series, 'X');
newY = filterRange(newY, series, 'Y');
if (dragPoint.index > 0 && (newX - dragPoint.series.data[dragPoint.index - 1].x) < dragMaxToPoint || dragPoint.index < dragPoint.series.data.length - 1 && (newX - dragPoint.series.data[dragPoint.index + 1].x) > -dragMaxToPoint) {
toClose = true; // DETECT POINT BEING DRAGGED PAST ANOTHER
}
if (Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2)) > dragSensitivity) {
return {
x: draggableX ? newX : dragPoint.x,
y: draggableY ? newY : dragPoint.y
};
} else {
return null;
}
}
Any ideas?
javascript highcharts
javascript highcharts
asked Nov 28 '18 at 11:42
KoiskiKoiski
3182620
3182620
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
How about sorting data after drop event and then use series.setData to update the chart:
plotOptions: {
series: {
point: {
events: {
drop: function() {
var series = this.series,
xData = series.xData.slice(),
yData = series.yData.slice(),
newData = ;
xData.forEach(function(data, i) {
newData.push([
data,
yData[i]
]);
});
newData.sort(function(a, b) {
return a[0] - b[0];
});
series.setData(newData, false, false);
series.chart.redraw();
}
}
},
stickyTracking: false
},
}
Demo:
http://jsfiddle.net/BlackLabel/6kyt3roL/
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53518657%2fhighcharts-redraw-and-sort-data-on-draggable-line-graph%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
How about sorting data after drop event and then use series.setData to update the chart:
plotOptions: {
series: {
point: {
events: {
drop: function() {
var series = this.series,
xData = series.xData.slice(),
yData = series.yData.slice(),
newData = ;
xData.forEach(function(data, i) {
newData.push([
data,
yData[i]
]);
});
newData.sort(function(a, b) {
return a[0] - b[0];
});
series.setData(newData, false, false);
series.chart.redraw();
}
}
},
stickyTracking: false
},
}
Demo:
http://jsfiddle.net/BlackLabel/6kyt3roL/
add a comment |
How about sorting data after drop event and then use series.setData to update the chart:
plotOptions: {
series: {
point: {
events: {
drop: function() {
var series = this.series,
xData = series.xData.slice(),
yData = series.yData.slice(),
newData = ;
xData.forEach(function(data, i) {
newData.push([
data,
yData[i]
]);
});
newData.sort(function(a, b) {
return a[0] - b[0];
});
series.setData(newData, false, false);
series.chart.redraw();
}
}
},
stickyTracking: false
},
}
Demo:
http://jsfiddle.net/BlackLabel/6kyt3roL/
add a comment |
How about sorting data after drop event and then use series.setData to update the chart:
plotOptions: {
series: {
point: {
events: {
drop: function() {
var series = this.series,
xData = series.xData.slice(),
yData = series.yData.slice(),
newData = ;
xData.forEach(function(data, i) {
newData.push([
data,
yData[i]
]);
});
newData.sort(function(a, b) {
return a[0] - b[0];
});
series.setData(newData, false, false);
series.chart.redraw();
}
}
},
stickyTracking: false
},
}
Demo:
http://jsfiddle.net/BlackLabel/6kyt3roL/
How about sorting data after drop event and then use series.setData to update the chart:
plotOptions: {
series: {
point: {
events: {
drop: function() {
var series = this.series,
xData = series.xData.slice(),
yData = series.yData.slice(),
newData = ;
xData.forEach(function(data, i) {
newData.push([
data,
yData[i]
]);
});
newData.sort(function(a, b) {
return a[0] - b[0];
});
series.setData(newData, false, false);
series.chart.redraw();
}
}
},
stickyTracking: false
},
}
Demo:
http://jsfiddle.net/BlackLabel/6kyt3roL/
answered Nov 28 '18 at 15:52
Wojciech ChmielWojciech Chmiel
2,3461212
2,3461212
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53518657%2fhighcharts-redraw-and-sort-data-on-draggable-line-graph%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown