【问题标题】:How to Reverse Chart.js Label Order?如何反转 Chart.js 标签顺序?
【发布时间】:2017-07-06 14:54:39
【问题描述】:

我使用了很多饼图和圆环图,其中包含两个数据值 项目。由于图表切片从 顶部顺时针方向,标签最终看起来颠倒:相反 它所代表的数据的一侧。

有没有一种简单的方法可以反转标签顺序,或者将图表反转为 逆时针运行?

new Chart(context, {
  type: 'doughnut',
  data: {
    labels: [ 'Blue', 'Red' ],
    datasets: [
      {
        data: [7, 3],
        backgroundColor: [
          'rgba(54, 162, 235, 0.7)',
          'rgba(208, 54, 100, 0.7)',
        ],
      },
    ]
  }
});

【问题讨论】:

标签: javascript charts chart.js


【解决方案1】:

我认为您正在寻找的是图例下的 reverse 选项,它将以相反的顺序显示数据集

http://www.chartjs.org/docs/latest/configuration/legend.html?h=reverse

【讨论】:

  • 是的,这正是我想要的。谢谢!
  • 很高兴能帮上忙!
【解决方案2】:

尝试在 Chart 对象中通过options 给它rotation

new Chart(context, {
type: 'doughnut',
data: {
labels: [ 'Blue', 'Red' ],
datasets: [{
          data: [7, 3],
          backgroundColor: [
          'rgba(54, 162, 235, 0.7)',
          'rgba(208, 54, 100, 0.7)',
          ],
      }]
     },
  options: {rotation: (0.5 * Math.PI)}
});

小提琴:https://jsfiddle.net/zdh7591r/

【讨论】:

  • 谢谢,这很有趣,但不是我问的。
猜你喜欢
  • 1970-01-01
  • 2021-11-18
  • 2016-05-09
  • 2021-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-26
  • 1970-01-01
相关资源
最近更新 更多