-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding and removing chart series confuses Highcharts #1
Comments
Wow, this is strange. I boiled it down to this: def toggle():
chart.options['series'] = [{'data': [1]}, {'data': [2]}] if len(chart.options['series']) == 1 else [{'data': [1]}]
chart.update()
chart = ui.chart({'series': [{'data': [1]}]})
ui.button('Toggle', on_click=toggle) Even though the options always contain a data point at 1, toggling multiple times leads to a single point at 2. I wonder if we can reproduce the problem with a pure Highcharts example without NiceGUI... |
No, without NiceGUI the example is working: <script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container"></div>
<button onclick="toggle()">Toggle</button>
<script>
let chart = Highcharts.chart("container", { series: [{ data: [1] }] });
function toggle() {
if (chart.series.length === 1) {
chart.addSeries({ data: [2] });
} else {
chart.series[1].remove();
}
}
</script> Now I'm pretty sure the issue is caused by |
Minimum reproduction without NiceGUI (but with the same update algorithm from chart.js): <html>
<head>
<script src="https://code.highcharts.com/highcharts.js"></script>
</head>
<body>
<div id="container"></div>
<button onclick="toggle()">Toggle</button>
<script>
let options = { series: [{ data: [1] }] };
let chart = Highcharts.chart("container", options);
let seriesCount = options.series ? options.series.length : 0;
function toggle() {
if (options.series.length === 1) {
options.series.push({ data: [2] });
} else {
options.series.pop();
}
update();
}
function update() {
while (seriesCount > options.series.length) {
chart.series[0].remove();
seriesCount--;
}
while (seriesCount < options.series.length) {
chart.addSeries({}, false);
seriesCount++;
}
chart.update(options);
}
</script>
</body>
</html> The question is, how to improve the |
I created a test page for manipulating Highcharts options: test.html<html>
<head>
<script src="https://code.highcharts.com/highcharts.js"></script>
</head>
<body>
<div id="container"></div>
<button onclick="insert_low()">Insert low</button>
<button onclick="insert_high()">Insert high</button>
<button onclick="remove_low()">Remove low</button>
<button onclick="remove_high()">Remove high</button>
<button onclick="reset()">Reset</button>
<button onclick="clear_all()">Clear</button>
<script>
let options = { series: [{ data: [0] }, { data: [1] }, { data: [2] }] };
let seriesCount = options.series.length;
let chart = Highcharts.chart("container", options);
function insert_low() {
options.series.unshift({ data: [options.series[0].data[0] - 1] });
update();
}
function insert_high() {
options.series.push({ data: [options.series[options.series.length - 1].data[0] + 1] });
update();
}
function remove_low() {
options.series.shift();
update();
}
function remove_high() {
options.series.pop();
update();
}
function reset() {
options.series = [{ data: [0] }];
update();
}
function clear_all() {
options.series = [];
update();
}
function update() {
while (seriesCount > options.series.length) {
chart.series[0].remove();
seriesCount--;
}
while (seriesCount < options.series.length) {
chart.addSeries({}, false);
seriesCount++;
}
chart.update(options);
}
</script>
</body>
</html> Currently all series collapse into a point at -1 when clicking "insert low". |
I still don't have a good solution for fixing this issue. |
I'm currently thinking about how to solve an update like this: <html>
<head>
<script src="https://code.highcharts.com/highcharts.js"></script>
</head>
<body>
<div id="container"></div>
<button onclick="add()">Add</button>
<script>
let options = { series: [{ data: [1] }, { data: [2] }, { data: [3] }] };
let chart = Highcharts.chart("container", options);
function add() {
options.series.unshift({ data: [0] });
chart.update(options);
}
</script>
</body>
</html> The chart simply collapses, which doesn't make any sense and looks like a bug in Highcharts. But it's hard to find a related bug report. This one might be relevant, maybe not. With 1.1K open and 13K closed issues it's hard to tell if this behavior is known and/or already worked on. By the way: A conversation with their AI didn't yield much insight. |
Description
In the screenshot attached you see:
this is a bug because they should be the same.
how to reproduce
This video shows the same thing. Regrettably, the capture window did not capture the deselections and selections of the same element - https://www.youtube.com/watch?v=KOKuhgMA9dk
The text was updated successfully, but these errors were encountered: