【问题标题】:Change % gauge chart to exact value in c3.js在 c3.js 中将百分比仪表图表更改为精确值
【发布时间】:2015-01-16 05:06:53
【问题描述】:

我正在尝试更改仪表图的单位。而不是默认显示 % 值,我想显示确切的值。我在文档中查找了它,但它不完整,我不确定我应该在代码中输入哪个值来更改它。

var chart = c3.generate({
bindto: "#chart",
data: {
    columns: [
        ['data', 15.0]
    ],
    type: 'gauge',
},
gauge: {
    min: 50,
    max: 100,
    units: '%' //I want to change that
}
});

【问题讨论】:

    标签: javascript c3.js


    【解决方案1】:

    我正在回答自己。要获得准确的值而不是仪表图中的 %,有必要添加以下行:

    var chart = c3.generate({
        bindto: "#chart",
        data: {
        columns: [
            ['data', 15.0]
         ],
        type: 'gauge',
        },
        gauge: {
        label:{
        format: function(value, ratio){
          return value; //returning here the value and not the ratio
          },
        },
        min: 50,
        max: 100,
        units: '%' //this is only the text for the label
        }
    });
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-09
    • 1970-01-01
    相关资源
    最近更新 更多