简体   繁体   English

高图-负值的饼图

[英]Highcharts - Pie chart with negative values

Is there any way of avoiding this unusual behavior in Highcharts? 有什么办法可以避免Highcharts中这种异常行为?

It happens when we update the chart with negative values on pie (donut) charts. 当我们用饼图(圆饼)上的负值更新图表时,就会发生这种情况。 Not on load. 未加载。

Highcharts饼,其中一个量表显示出蠕变行为

In general, if you have negative values in the data that you are displaying, use a bar chart instead of a pie chart. 通常,如果所显示的数据中包含负值,请使用条形图而不是饼图。 Pie charts are supposed to represent a part of a total, a part-to-whole relationship, thus negative numbers won't work because you can't have a negative part of a total. 饼图应该代表总数的一部分,是部分与整个关系,因此负数将不起作用,因为您不能在总数中具有负数。

In case that you actually want to just show that value, try wrapping it in an absolute value; 如果您实际上只想显示该值,请尝试将其包装在绝对值中;

 plotOptions: {
     pie: {
        allowPointSelect: true,
        cursor: 'pointer',
        dataLabels: {
           enabled: true,
           formatter: function() {
               return this.point.positive ? this.y : this.y * (-1);// <-- or wrap in absolute Math.abs(this.y)
           },
           color: 'black',
           style: {
              font: '13px Trebuchet MS, Verdana, sans-serif'
           }
        }
     }
  }

JSFiddle 的jsfiddle

根据github线程,这应该在最新的master分支中解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM