Advertisement
borsha06

klkl

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