Chartjs-plugin-datalabels: Use chartjs-plugin-datalabels with vue-chartjs

Created on 26 Oct 2017  路  7Comments  路  Source: chartjs/chartjs-plugin-datalabels

Hi, i am actually trying to add this plugin to a vue.js project using vue-chartjs and i have no idea how to do it. I installed chartjs-plugin-datalabels using node but then what should i do?

resolved support

Most helpful comment

Ok, sorry for the wait i finally managed to get some time to explain how i did it (it's actually pretty simple)
-Install chartJsPluginDataLabels via npm:

npm install chartjs-plugin-datalabels --save

-import it as a component in your vue:

import ChartJsPluginDataLabels from 'chartjs-plugin-datalabels';

var app = new Vue({
  el: '#app',
  data: {
    message: 'Hello Vue!'
  },
  components: {
    ChartJsPluginDataLabels,
  },
})

and there it is, you should have datalabels on your vue-chartjs :)
if you want to change any options on your charts it's just like the regular chartjs : https://chartjs-plugin-datalabels.netlify.com/options.html

All 7 comments

I'm not familiar with Vue.js or vue-chartjs, did that thread help?

You will probably need vue-chartjs 2.8.7 (since this plugin requires Chart.js 2.7) and thus Vue.js 2.4.4. Then I'm not sure what is the best way to import JavaScript libraries in Vue.js, maybe simply load it via a <script> tag (so no need of the node.js package) (example):

<!-- index.html -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>

It may be better to ask this question on the vue-chartjs project and link to that ticket.

@HenriSup did you progress on that integration?

Yes sorry for the silence it was actually pretty simple just installed it via npm and imported it the way you import component in vue.js and it was on all my charts, just had to add some parameters via the data.plugin.etc.... but I'm not at work this week I'm only telling this by memory. Should I close the topic or would it be better if I add more precision and a clear way to explain how I did when I'll be back at my workplace?

Sounds great! It's a good idea to document more precisely the way you get it working, that could help other Vue.js users who want to use this plugin.

Ok, sorry for the wait i finally managed to get some time to explain how i did it (it's actually pretty simple)
-Install chartJsPluginDataLabels via npm:

npm install chartjs-plugin-datalabels --save

-import it as a component in your vue:

import ChartJsPluginDataLabels from 'chartjs-plugin-datalabels';

var app = new Vue({
  el: '#app',
  data: {
    message: 'Hello Vue!'
  },
  components: {
    ChartJsPluginDataLabels,
  },
})

and there it is, you should have datalabels on your vue-chartjs :)
if you want to change any options on your charts it's just like the regular chartjs : https://chartjs-plugin-datalabels.netlify.com/options.html

Thanks @HenriSup for the follow up!

I've added it to components property of my single file component, but it got applied to all my components, how can I define a scope for this?
Edit: I've solved it https://github.com/chartjs/chartjs-plugin-datalabels/issues/188

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wjohnsto picture wjohnsto  路  12Comments

ed1nh0 picture ed1nh0  路  10Comments

ericsvendsen picture ericsvendsen  路  15Comments

012attack picture 012attack  路  8Comments

timdiggins picture timdiggins  路  8Comments