Advertisement
vitareinforce

Line Chart Vue Chart

Sep 13th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. // buat file di folder plugins/vue-chart.js
  2. // isinya
  3.  
  4. import Vue from 'vue'
  5.  
  6. import 'chart.js/dist/Chart.bundle.min.js'
  7. import VueCharts from 'vue-chartjs'
  8.  
  9. Vue.use(VueCharts)
  10.  
  11. // template per komponent chartjs
  12. // buat file di components/linechart.vue
  13. isinya
  14.  
  15. <script>
  16. import { Line } from 'vue-chartjs'
  17. export default {
  18. extends: Line,
  19. props: ['data', 'options'],
  20. mounted () {
  21. this.renderChart(this.data, this.options)
  22. }
  23. }
  24. </script>
  25.  
  26. // cara pake di html
  27. <linechart :data="linecollection"/>
  28.  
  29. // di <script vue>
  30. import linechart from '@/components/linechart
  31.  
  32. // di dalem method data
  33. data () {
  34. return {
  35. linecollection: {
  36. labels: ['Label 0', 'Label 1', 'Label 2'],
  37. datasets: [
  38. {
  39. label: 'Data One',
  40. borderColor: 'rgba(50, 115, 220, 0.5)',
  41. backgroundColor: 'rgba(50, 115, 220, 0.1)',
  42. data: [33, 55, 44]
  43. },
  44. {
  45. label: 'Data Two',
  46. borderColor: 'rgba(220, 55, 115, 0.1)',
  47. backgroundColor: 'rgba(220, 55, 115, 0.5)',
  48. data: [44, 33, 55]
  49. }
  50. ]
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement