Advertisement
borsha06

ll

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