Change % gauge chart to exact value in c3.js

╄→гoц情女王★ 提交于 2019-12-21 18:31:45

问题


I am trying to change the units of a gauge chart. Instead of showing the % value by default, I would like to show the exact value. I looked for that in the documentation but it is incomplete and I am not sure which value I should put in the code to change it.

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

回答1:


I am answering myself. To get the exact value and not the % one in a gauge chart, it is necessary to add this lines:

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
    }
});


来源:https://stackoverflow.com/questions/27004001/change-gauge-chart-to-exact-value-in-c3-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!