Advertisement
borsha06

ooo

May 11th, 2018
168
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.                         barThickness: 50,
  21.                         mirror: true
  22.                     }
  23.                 }]
  24.             },
  25.         },
  26.         /*gridLines: {
  27.             display: false
  28.         }
  29.     }],
  30.     gridLines: {
  31.         display: true
  32.     }
  33. },
  34.  
  35.          legend: {
  36.              display: false
  37.          },
  38. tooltips: {
  39. enabled: true,
  40. mode: 'single',
  41. callbacks: {
  42.     label: function(tooltipItems, this.keys) {
  43.         return '$' + tooltipItems.yLabel;
  44.     }
  45. }
  46. },
  47. */
  48.         responsive: true,
  49.         maintainAspectRatio: false
  50.  
  51.     }),
  52.     created () {
  53.  
  54.         // Overwriting base render method with actual data.
  55.         this.$http({
  56.             method: 'get',
  57.             url: this.base_url + '/exam/api/score/' + this.$store.state.user.id + '/',
  58.  
  59.             auth: {
  60.                 username: 'l360_mobile_app',
  61.                 password: 'itsd321#'
  62.             },
  63.         }).then(res => {
  64.  
  65.             console.log(res);
  66.             if (res.status == '200') {
  67.                 console.log(res.data);
  68.                 this.score = res.data;
  69.                 for (let v  in  this.score) {
  70.                     this.value.push(this.score[v]);
  71.                 }
  72.                 for (let key  in  this.score) {
  73.                     this.keys.push(key);
  74.                 }
  75.  
  76.  
  77.                 console.log(this.keys);
  78.                 console.log(this.value);
  79.             }
  80.         });
  81.         this.fillData()
  82.  
  83.     },
  84.     mounted(){
  85.         this.renderChart(this.chartData, this.options);
  86.  
  87.  
  88.     },
  89.  
  90.     methods: {
  91.  
  92.         fillData ()  {
  93.             this.chartData = {
  94.  
  95.                 labels: this.keys,
  96.  
  97.                 datasets: [
  98.                     {
  99.                         label: "Label One",
  100.                         backgroundColor: '#f87979',
  101.                         data: this.value,
  102.  
  103.                     }
  104.  
  105.                 ],
  106.  
  107.             }
  108.         }
  109.     },
  110.     watch: {
  111.         data: function () {
  112.             this._chart.destroy();
  113.             this.renderChart(this.chartData, this.options);
  114.         },
  115.     },
  116.  
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement