angular-highcharts icon indicating copy to clipboard operation
angular-highcharts copied to clipboard

Support for themes?

Open gustavostuff opened this issue 8 years ago • 13 comments

Does this plugin have theme support? it would be nice to have a way of doing something like this directly with Angular.

gustavostuff avatar Sep 06 '17 00:09 gustavostuff

@tavuntu yes, the following should work.

import { Highcharts } from 'angular-highcharts';

// Apply the theme
Highcharts.setOptions(Highcharts.theme);

cebor avatar Sep 06 '17 08:09 cebor

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';

gustavostuff avatar Sep 06 '17 15:09 gustavostuff

To resolve this issue i need more code to dig into this. Can you setup a minimal repo or Plunkr?

cebor avatar Sep 07 '17 08:09 cebor

here you go, I'm using npm 5.4.0 and the latest version of angular-highcharts https://github.com/tavuntu/general-stuff

gustavostuff avatar Sep 07 '17 15:09 gustavostuff

Was this issue resolved? Is there any workaround?

SayakMukhopadhyay avatar Mar 03 '18 12:03 SayakMukhopadhyay

@SayakMukhopadhyay I haven't tested this since then (I switched to Chart.js), are seeing the issue?

gustavostuff avatar Mar 04 '18 19:03 gustavostuff

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.

SayakMukhopadhyay avatar Mar 05 '18 09:03 SayakMukhopadhyay

UPDATE: The procedure mention in https://github.com/cebor/angular-highcharts/issues/59#issuecomment-327407520 is working in Angular 5. Tried and tested!

SayakMukhopadhyay avatar Mar 05 '18 19:03 SayakMukhopadhyay

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?

dereklin avatar Oct 23 '18 02:10 dereklin

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

SayakMukhopadhyay avatar Oct 23 '18 08:10 SayakMukhopadhyay

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?

dereklin avatar Oct 24 '18 05:10 dereklin

Yup. Recreating the chart object is the only way to change the theme as far as what I have found.

SayakMukhopadhyay avatar Oct 24 '18 06:10 SayakMukhopadhyay

I was able to get it working like this:

this.chart = new Chart({...});
this.chart.theme = {...};
Highcharts.setOptions(this.chart.theme);

wiggitamoo avatar Nov 09 '18 16:11 wiggitamoo