From 0fe32835c96c7c3c6b8fdde820444d29e1a98dbb Mon Sep 17 00:00:00 2001 From: TechMiX Date: Fri, 23 Oct 2020 19:03:15 +0200 Subject: [PATCH] update legend state after chart update --- .../components/statistics/chartist.component.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/components/statistics/chartist.component.ts b/frontend/src/app/components/statistics/chartist.component.ts index c53784190..2ebad2698 100644 --- a/frontend/src/app/components/statistics/chartist.component.ts +++ b/frontend/src/app/components/statistics/chartist.component.ts @@ -314,6 +314,13 @@ Chartist.plugins.legend = function (options: any) { return function legend(chart: any) { + var isClicked = false; + + chart.on('created', function (data: any) { + + if (isClicked) + return; + function removeLegendElement() { const legendElement = chart.container.querySelector('.ct-legend'); if (legendElement) { @@ -442,7 +449,9 @@ Chartist.plugins.legend = function (options: any) { chart.data.labels = newLabels; } + isClicked = true; chart.update(); + isClicked = false; if (options.onClick) { options.onClick(chart, e); @@ -480,14 +489,13 @@ Chartist.plugins.legend = function (options: any) { }); }); - chart.on('created', function (data: any) { - appendLegendToDOM(legendElement); - }); + appendLegendToDOM(legendElement); if (options.clickable) { setSeriesClassNames(); addClickHandler(legendElement, legends, seriesMetadata, useLabels); } + }); }; };