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

how to enforce the max value on y axis #236

Closed
abc245 opened this issue Oct 26, 2017 · 1 comment
Closed

how to enforce the max value on y axis #236

abc245 opened this issue Oct 26, 2017 · 1 comment

Comments

@abc245
Copy link

abc245 commented Oct 26, 2017

Hi there,

it's not really an issue, but a question. How can I enforce the max value on Y axis. Currently I define it as follows

<LineChart :chart-data="data" :yTicks="{min: 0, max: 5}" :height="300" />

However the max Y value changes according to the data.

I reuse LineChart component in several places and want to have a flexibility of defining the max Y value.

The LineChart component looks as follows:

import { Line } from 'vue-chartjs'

export default Line.extend({
  props: ['chartData', 'labelname'],
  mounted () {
    // Overwriting base render method with actual data.
    this.renderChart(this.chartData, {
      responsive: true,
      legend: {
        // display: false
      },
      layout: {
        padding: 10
      },
      scales: {
        xAxes: [{
          gridLines: {
            display: true
          }
        }],
        yAxes: [{
          gridLines: {
            display: true
          }
        }]
      }
    })
  }
})

Thanks

@apertureless
Copy link
Owner

apertureless commented Oct 28, 2017

Well your example does not make any sense 🙈
You are passing a prop named yTicks to your line-chart but you don't define it anywhere. oO
You need to define the prop and then you can pass it to the options.

import { Line } from 'vue-chartjs'

export default Line.extend({
  props: ['chartData', 'labelname', 'yTicks'],
  mounted () {
    // Overwriting base render method with actual data.
    this.renderChart(this.chartData, {
      responsive: true,
      legend: {
        // display: false
      },
      layout: {
        padding: 10
      },
      scales: {
        xAxes: [{
          gridLines: {
            display: true
          }
        }],
        yAxes: [{
          gridLines: {
            display: true
          },
          ticks: {
           min: this.yTicks.min,           
           max: this.yTicks.max,
          }
        }]
      }
    })
  }
})

And then

<line-chart :chart-data="data" :y-ticks="{min: 0, max: 5}" :height="300" />

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