Skip to content
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

Set global options and override defaults #105

Closed
Diferno opened this issue May 17, 2019 · 8 comments
Closed

Set global options and override defaults #105

Diferno opened this issue May 17, 2019 · 8 comments

Comments

@Diferno
Copy link

Diferno commented May 17, 2019

Hi!
I'm trying to override the default options of the charts (to set the fontfamily for all the legends, axis, etc...) but can't find the correct way to do so.

I have my plugin registered as:

  Vue.use(VueApexCharts)
  Vue.component('apexchart', VueApexCharts)

And have tryed to override like:

VueApexCharts.chartOptions = Object.assign(VueApexCharts.chartOptions, {
    xaxis: {
      labels: {
        style: {
          fontFamily: 'Montserrat'
        }
      }
    }
  })

And even trying to set the defaults as I do with axios through
VueApexCharts.props.options

Any tips?
Thx in advance!

@junedchhipa
Copy link
Contributor

Can you try setting the global Apex variable?

Apex.xaxis = {
   labels: {
     style: {
          fontFamily: 'Montserrat'
      }
   }
}

This would override the default settings for the x-axis.
Let me know if it worked.

@junedchhipa junedchhipa changed the title Override default options in plugin Set global options and override defaults May 17, 2019
@joshhoegen
Copy link

joshhoegen commented Jul 3, 2019

@Diferno, any luck with @junedchhipa's suggestion?

@junedchhipa, are you suggesting that Apex === VueApexCharts if using Diferno's syntax? If so, that's not working for me.

@junedchhipa
Copy link
Contributor

Apex !== VueApexCharts

window.Apex is a global variable and it should be set after importing and registering Vue-ApexCharts using

Vue.use(VueApexCharts)
window.Apex.xaxis = { ... }

After this, when you use <apexcharts> component, it will get the default values first from window.Apex and then use your chart's config.

@joshhoegen
Copy link

Oooohhhh! Thank you very much for this insight, @junedchhipa! This will be beneficial for app light/dark theming!

@sajaddp
Copy link

sajaddp commented Oct 22, 2019

@junedchhipa,
Can you help me to change all font-family attributes globally?

@junedchhipa
Copy link
Contributor

@sajaddp
To set font-family for all elements of the chart, you can use

options = {
   chart: {
      fontFamily: 'Courier New', Courier, monospace
   }
}

@alarhoo
Copy link

alarhoo commented Nov 22, 2020

Apex !== VueApexCharts

window.Apex is a global variable and it should be set after importing and registering Vue-ApexCharts using

Vue.use(VueApexCharts)
window.Apex.xaxis = { ... }

After this, when you use <apexcharts> component, it will get the default values first from window.Apex and then use your chart's config.

How can we do it for ng-apexcharts?

window.Apex has no data.

@phamhunker
Copy link

phamhunker commented Jul 25, 2023

I know this ticket is closed and a bit old - but it was one of the first posts i found, so posting it here in case anyone else runs into this and needs help.

For anyone using ng-apexcharts, doing global options is simply...

    apexChart = window['Apex'] as ApexOptions;
    this.apexChart.chart = {
      type: 'line',
      toolbar: {
        show: true,
       ...
      },
      zoom: {
        enabled: false,
      },
    };

    this.apexChart.legend = {
      show: true,
      ...
    };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants