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

Legend or other options not working in reactiveProps #188

Closed
AshwinTayson opened this issue Sep 5, 2017 · 7 comments
Closed

Legend or other options not working in reactiveProps #188

AshwinTayson opened this issue Sep 5, 2017 · 7 comments

Comments

@AshwinTayson
Copy link

I have followed the code sample in the website and created a lineChart.js that looks like this

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

export default Line.extend({
  mixins: [mixins.reactiveProp],
  props: ['chartData'],
  mounted () {
    this.renderChart(this.chartData, {
      legend: {
        display: false
      }
    })
  }
})

Expected Behavior

Legend should be disabled. And other options such as tooltip, responsive should work.

Actual Behavior

Chart works as intended but the legend is still showing. Any other options delivered to this.renderChart is not working.

Environment

  • vue.js version: 2.3.3
  • vue-chart.js version: 0.2.0
  • npm version: 5.0.3
@apertureless
Copy link
Owner

This will not work this way.

You have to pass the options either as a prop or data model

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

export default Line.extend({
  mixins: [mixins.reactiveProp],
  props: ['chartData'],
  data () {
    return {
      options: {
        legend: {
          display: false
        }
      }
    }
  }
  mounted () {
    this.renderChart(this.chartData, this.options)
  }
})

This is because the reactive prop will check what data changed and either call chart.update or if new datasets arrived it will call this.renderChart(this.chartData, this.options)

As it is the base class, there is no way AFAIK to check that you are passing there. Thats why you need to store your options in options variable.

@naknode
Copy link

naknode commented Sep 6, 2017

Trying to pass scaleShowGridLines: true and it does not work for me. :\

@apertureless
Copy link
Owner

@naknode

Please show the code snippet or codepen/jsfiddle/webpackbin etc.

@naknode
Copy link

naknode commented Sep 6, 2017

Sure @apertureless

Here:

import { Bar } from 'vue-chartjs'

export default Bar.extend({
  mounted () {
    // Overwriting base render method with actual data.
    this.renderChart({
      labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
      datasets: [
        {
          label: 'GitHub Commits',
          backgroundColor: '#f87979',
          data: [40, 20, 12, 39, 10, 40, 39, 80, 40, 20, 12, 11]
        }
      ]
    }, {
      scaleShowGridLines: true,
      scaleGridLineColor: "rgba(0,0,0,.05)",
      scaleGridLineWidth: 1,
      scaleShowHorizontalLines: true,
      scaleShowVerticalLines: true,
      barShowStroke: true,
      barStrokeWidth: 2,
      barValueSpacing: 5,
      barDatasetSpacing: 1,
      legend: {
        display: true
      }
    })
  }
})

and

        <template>
          <dash-chart role="user" :width="500" :height="400" />
        </template>

I copied the data from the GitHub commits, and this is what I get:

image

@apertureless
Copy link
Owner

Well I can't find anything about scaleGridLineWidth in the Chart.js docs. Where did you found this?

@naknode
Copy link

naknode commented Sep 6, 2017

I believe I was using an incorrect version.

I apologize.

I got it to work:

    scales : {
        xAxes : [ {
            gridLines : {
                display : true
            }
        } ]
    },

@apertureless
Copy link
Owner

nice!

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

3 participants