angular-highcharts
angular-highcharts copied to clipboard
Support for themes?
Does this plugin have theme support? it would be nice to have a way of doing something like this directly with Angular.
@tavuntu yes, the following should work.
import { Highcharts } from 'angular-highcharts';
// Apply the theme
Highcharts.setOptions(Highcharts.theme);
The object Highcharts is undefined when importing it, so it throws an error when trying to use .theme or .setOptions(). I've added the ChartModule un app.moduel.ts, maybe I'm missing something else?
EDIT: this results in an undefined object as well... weird:
import { Highcharts } from 'highcharts';
To resolve this issue i need more code to dig into this. Can you setup a minimal repo or Plunkr?
here you go, I'm using npm 5.4.0 and the latest version of angular-highcharts https://github.com/tavuntu/general-stuff
Was this issue resolved? Is there any workaround?
@SayakMukhopadhyay I haven't tested this since then (I switched to Chart.js), are seeing the issue?
Yeah, I am. I am planning on the only workaround of loading the theme js in the header for now. Using setOptions is more flexible though.
UPDATE: The procedure mention in https://github.com/cebor/angular-highcharts/issues/59#issuecomment-327407520 is working in Angular 5. Tried and tested!
Highcharts.setOptions(Highcharts.theme); seems to affect the new charts after it.
What would the easiest way to refresh the charts so that the new theme is applied immediately to existing charts?
If you don't mind looking through source code, I have implemented a dynamic theme switcher in https://github.com/SayakMukhopadhyay/elitebgs . This is the service file . The theme switch is triggered in this component and the chart is rendered in this component
Interesting, so you are basically recreating the chart when switching themes right?
this.themeService.theme$.subscribe(theme => {
this.chart = new Chart(this.options);
});
By doing
this.linkRef.onload = () => this.themeService.themeLoaded();
and
this.linkRef.href = this.themeService.getTheme().href;
You are loading the style sheet related to the theme dynamically and also triggering the theme change, right?
Yup. Recreating the chart object is the only way to change the theme as far as what I have found.
I was able to get it working like this:
this.chart = new Chart({...});
this.chart.theme = {...};
Highcharts.setOptions(this.chart.theme);