Vuejs - Chartjs - 将圆环图转换为标尺 - 旋转

时间:2018-06-01 09:31:21

标签: vue.js vuejs2 chart.js vue-component vue-chartjs

我是vue.js的新手,非常感谢您的帮助和建议。

我正在使用Chartjs,我想旋转我的饼图,使它看起来像一个仪表。我不确定我的javascript错误在哪里,我在控制台中没有错误 - 有人可以建议我

我不确定我是否没有放置"选项"在正确的地方

chartjs.html

<div class="wrapper">
  <div class="chart_header">chartjs guage</div>
  <vue-chartsguagejs></vue-chartsguagejs>
</div>

chartsjsgauge.js

import { Doughnut } from 'vue-chartjs'

export default {
  extends: Doughnut,
  mounted () {
    this.renderChart({
      labels: ["Log Level", "Debug", "Info", "Warn", "Error", "Fatal"],
      datasets: [{
        label: 'GitHub Commits',
        backgroundColor: ['rgb(255, 255, 255)', 'rgb(232,226,202)', 'rgb(226,210,172)', 'rgb(223,189,139)', 'rgb(223,162,103)','rgb(226,126,64)'],
        borderWidth: 0,
        hoverBorderWidth: 0,
        data: [50, 10, 10, 10, 10, 10],
      }],
      options: {
        cutoutPercentage: 0,
        rotation: -3.1415926535898,
        circumference: 3.1415926535898,
      }
    }, {responsive: true, maintainAspectRatio: false})
  }
}

这是我目前的dougnut图表,我试图将其作为一个标准旋转 enter image description here

1 个答案:

答案 0 :(得分:-1)

我发现以这种格式重构我的代码产生了巨大的差异:

import { Doughnut } from 'vue-chartjs'

export default {
  extends: Doughnut,
  data () {
    return {
      datacollection: {
        labels: ["Log Level", "Debug", "Info", "Warn", "Error", "Fatal"],
        datasets: [
          {
            label: 'GitHub Commits',
            backgroundColor: ['rgb(226,126,64)', 'rgb(232,226,202)', 'rgb(226,210,172)', 'rgb(223,189,139)', 'rgb(223,162,103)','rgb(226,126,64)'],
            borderWidth: 0,
            hoverBorderWidth: 0,
            data: [10, 10, 10, 10, 10],
          }
        ]
      },
      options: {
        rotation: -1.0 * Math.PI,
        circumference: Math.PI,
      }

    }
  },
  mounted () {
    this.renderChart(this.datacollection, this.options, {responsive: true, maintainAspectRatio: false})
  }
}

enter image description here