Chartjs-Vue.js: How to retrieve data from API for vue chart.js

1πŸ‘

βœ…

I don’t really understand your question. You have to transform your data, to fit the schema of chart.js

You can however add multiple datasets. The question is what are you trying to achieve.

import { Line } from 'vue-chartjs';

export default {
extends: Line,
mounted () {
this.renderChart({
  labels: ['2018-02', '2018-03'],
  datasets: [
    {
      label: 'umin',
      backgroundColor: '#f87979',
      data: [12481, 12590]
    },
    {
      label: 'umax',
      backgroundColor: '#f87979',
      data: [12581, 12590]
    },
    {
      label: 'umedian',
      backgroundColor: '#f87979',
      data: [12527, 12590]
    }
   ]
  }, {responsive: true, maintainAspectRatio: false})
 }
};

The labels: array is your X axis.
The data array in your datasets object, is your Y value for the corresponding X value.

╔═════════╦════════════╦═════════════╗
β•‘         β•‘ 2018-02    β•‘ 2018-03     β•‘
╠═════════╬════════════╬═════════════╣
β•‘ umin    β•‘ 12481      β•‘ 12590       β•‘
β•‘ umax    β•‘ 12581      β•‘ 12590       β•‘
β•‘ umedian β•‘ 12527      β•‘ 12590       β•‘
β•šβ•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•β•β•β•

Leave a comment