How may I force a redraw of all Vaadin charts in a dashboard to toggle dataLabels on or off?

StackOverflow https://stackoverflow.com/questions/23643303

  •  22-07-2023
  •  | 
  •  

質問

How may I force a redraw of All Vaadin charts in a dashboard to toggle dataLabels on or off? I would like to allow my app user to add/remove chart dataLabels for All charts on their dashboard; forcing a redraw similar to when changing themes say from VaadinTheme to GridTheme.
How may I achieve this? How does changing themes work under the hood, what is the source code that does this? e.g.; I know I could redraw a single chart individually by resetting its plot options and then redrawing it: . . .

PlotOptionsColumnRange columnRange = new PlotOptionsColumnRange();
columnRange.setDataLabels(new Labels(true));      
columnRange.setDataLabels.setFormatter(/* some javascript about this.y */);
conf.setPlotOptions(columnRange);
chart.drawChart(conf);

But I want to do it for All charts on a dashboard; like having a Listener that does

ChartOptions.get().setTheme(new VaadinTheme())

then

ChartOptions.get().setTheme(new GridTheme())

and viceversa

Maybe I can reset the plotOption dataLabels then reset the theme to force a redraw with the new dataLabel state? Please advise...

p.s. I don't want to make changes to my user saved data in my database, i.e., I don't want this label toggle to be persistent. I want to toggle dataLabels just like a toggling themes. Please look at: http://demo.vaadin.com/charts/#ColumnRange to see what I mean.

役に立ちましたか?

解決

Ok, two solutions: A coworker of mine that worked on the Dashboards helped me with the first answer to this question. Basically, you have to clear all charts, then iterate through ea. chart in a particular dashboard (stored in the DB), and rebuild ea. chart w/ your decision to have or not have a dataLabel, placing it back in that dashboard; but I wanted to avoid this as it might take a performance hit.

Also I later got a response from Pekka of the Vadding team, as follows:

'You can easily hide the dataLabels with basic css. For example, if you can apply a stylename "dataLabelsHidden" to you UI, then you could write in your stylesheet a specific enough rule for hiding the labels. I quickly tested the demo with this:

.v-ui.dataLabelsHidden g.highcharts-data-labels {
    display: none;
}

This way you won't have to update all your charts when the labels on/off is triggered.'

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top