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

Options being ignored #160

Closed
peteringram0 opened this issue Jul 31, 2017 · 4 comments
Closed

Options being ignored #160

peteringram0 opened this issue Jul 31, 2017 · 4 comments

Comments

@peteringram0
Copy link

peteringram0 commented Jul 31, 2017

There seems to be an issue with disabling the legend with the latest version. This was working before for me.

Chart rendered:
screen shot 2017-07-31 at 16 22 46

Constants.js file

export default {
    chartOptions: {
        legend: {
            display: false
        }
    }
}

.vue file

import {
    Bar,
    mixins
} from 'vue-chartjs'

import Constants from '../../Constants';

const { reactiveData } = mixins;

export default Bar.extend({
    mixins: [reactiveData],
    data() { 
        return {
            chartData: null
        }
    },
    watch: {
        // watching my external data-set and updates this.chartData
    },
    mounted() {
        this.renderChart(this.chartData, Constants.chartOptions);
    }
});
@apertureless
Copy link
Owner

What was the previous version you were using?
Are you now using the latest?

@peteringram0
Copy link
Author

I am using the latest version now yes. Sorry what i about the previous version is in-accurate.

This is happening when using the reactiveData mixins. If i remove it the legend is hidden.

@apertureless
Copy link
Owner

Oh okay.
Yeah the chart options and the reactive mixins are a bit weird. Because in some cases, if you add new data and the chart can't update and has to re-render and it calls renderChart(this.chartData, this.options)

Right now I don't really know how to "clean" this up, because I don't know which arguments get passed from the user. So if you don't set your chart options in a local data attribute called options it will re-render the chart without options.

So a workaround for you would be to declare options in your data model.

import {
    Bar,
    mixins
} from 'vue-chartjs'

import Constants from '../../Constants';

const { reactiveData } = mixins;

export default Bar.extend({
    mixins: [reactiveData],
    data() { 
        return {
            chartData: null,
            options: Constants.chartOptions
        }
    },
    watch: {
        // watching my external data-set and updates this.chartData
    },
    mounted() {
        this.renderChart(this.chartData, this.options);
    }
});

This should fix it.

@peteringram0
Copy link
Author

Ah yer got it, thats working, thanks.

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

No branches or pull requests

2 participants