【问题标题】:Vuejs - Chartjs - turning a doughnut chart to a gauge - rotationVuejs - Chartjs - 将圆环图转换为仪表 - 旋转
【发布时间】:2018-11-11 09:54:05
【问题描述】:

我是 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})
  }
}

这是目前我的甜甜圈图表,我正在尝试将其旋转为量规

【问题讨论】:

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


    【解决方案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})
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-19
      • 1970-01-01
      • 2020-03-26
      • 1970-01-01
      • 1970-01-01
      • 2019-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多