Advertisement
borsha06

sld

May 12th, 2018
166
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.  
  39.         responsive: true,
  40.         maintainAspectRatio: false
  41.  
  42.     }),
  43.     created () {
  44.  
  45.         // Overwriting base render method with actual data.
  46.         this.$http({
  47.             method: 'get',
  48.             url: this.base_url + '/exam/api/score/' + this.$store.state.user.id + '/',
  49.  
  50.             auth: {
  51.                 username: 'l360_mobile_app',
  52.                 password: 'itsd321#'
  53.             },
  54.         }).then(res => {
  55.  
  56.             console.log(res);
  57.             if (res.status == '200') {
  58.                 console.log(res.data);
  59.                 this.score = res.data;
  60.                 for (let v  in  this.score) {
  61.                     this.value.push(this.score[v]);
  62.                 }
  63.                 for (let key  in  this.score) {
  64.                     this.keys.push(key);
  65.                 }
  66.  
  67.  
  68.                 console.log(this.keys);
  69.                 console.log(this.value);
  70.             }
  71.         });
  72.         this.fillData()
  73.  
  74.     },
  75.     mounted(){
  76.        /* this.addPlugin({
  77.             id: 'my-plugin',
  78.             beforeInit: function (chart) {
  79.  
  80.             }
  81.         });
  82.         */
  83.         this.renderChart(this.chartData, this.options);
  84.  
  85.  
  86.     },
  87.  
  88.     methods: {
  89.  
  90.         fillData ()  {
  91.             this.chartData = {
  92.  
  93.                 labels: this.keys,
  94.  
  95.                 datasets: [
  96.                     {
  97.                         fillColor: "#ffecbf",
  98.                         strokeColor: "#dacdd2",
  99.                         //backgroundColor: '#f87979',
  100.                         data: this.value,
  101.  
  102.                     }
  103.  
  104.                 ],
  105.  
  106.             }
  107.         }
  108.     },
  109.     watch: {
  110.         data: function () {
  111.             this._chart.destroy();
  112.             this.renderChart(this.chartData, this.options);
  113.         },
  114.     },
  115.  
  116.  
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement