Advertisement
borsha06

--|--h

May 11th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { HorizontalBar } from 'vue-chartjs'
  2.  
  3. export default {
  4.     name: 'diagram',
  5.     extends: HorizontalBar,
  6.     data: () => ({
  7.         chartData: '',
  8.         score: {},
  9.         value: [],
  10.         keys: [],
  11.         options: {
  12.             scales: {
  13.                 xAxes: [{
  14.                     ticks: {
  15.                         //beginAtZero: true
  16.                     }
  17.                 }],
  18.                 yAxes: [{
  19.                     ticks: {
  20.                         beginAtZero: true,
  21.                         barThickness: 50,
  22.                         mirror: true
  23.                     }
  24.                 }]
  25.             },
  26.             responsive: true,
  27.             legend: {
  28.                 display: false,
  29.             },
  30.         },
  31.  
  32.         responsive: true,
  33.         maintainAspectRatio: false
  34.  
  35.     }),
  36.     created () {
  37.  
  38.         // Overwriting base render method with actual data.
  39.         this.$http({
  40.             method: 'get',
  41.             url: this.base_url + '/exam/api/score/' + this.$store.state.user.id + '/',
  42.  
  43.             auth: {
  44.                 username: 'l360_mobile_app',
  45.                 password: 'itsd321#'
  46.             },
  47.         }).then(res => {
  48.  
  49.             console.log(res);
  50.             if (res.status == '200') {
  51.                 console.log(res.data);
  52.                 this.score = res.data;
  53.                 for (let v  in  this.score) {
  54.                     this.value.push(this.score[v]);
  55.                 }
  56.                 for (let key  in  this.score) {
  57.                     this.keys.push(key);
  58.                 }
  59.  
  60.  
  61.                 console.log(this.keys);
  62.                 console.log(this.value);
  63.             }
  64.         });
  65.         this.fillData()
  66.  
  67.     },
  68.     mounted(){
  69.         this.renderChart(this.chartData, this.options);
  70.  
  71.  
  72.     },
  73.  
  74.     methods: {
  75.  
  76.         fillData ()  {
  77.             this.chartData = {
  78.  
  79.                 labels: this.keys,
  80.  
  81.                 datasets: [
  82.                     {
  83.                         fillColor: "#1886d1",
  84.                         strokeColor: "#101a4d",
  85.                         label: "Label One",
  86.                         //backgroundColor: '#f87979',
  87.                         data: this.value,
  88.  
  89.                     }
  90.  
  91.                 ],
  92.  
  93.             }
  94.         }
  95.     },
  96.     watch: {
  97.         data: function () {
  98.             this._chart.destroy();
  99.             this.renderChart(this.chartData, this.options);
  100.         },
  101.     },
  102.  
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement