2017-04-20 30 views
0

格式化工具提示的数字,我想的格式将显示在工具提示这样的数字:如何使用ZingChart

var num = 0.1234567890; 
num.toFixed(4); 
"0.1235" 

我检查了documentation,但它主要是使用日期和大数

交易有没有办法做到这一点?

回答

1

ZingChart有一个decimals属性,可以在全局范围内格式化数字。这意味着如果在图中应用decimals属性,valueBox将继承此属性,tooltip也将如此。

plot: { 
    decimals: 4, 
    valueBox: { 

    } 
}... 

如果你这样做只是提示对象中你只会得到应用到提示截断值。

注意:JSON属性前面的下划线就像内联注释。

plot docs here

var myConfig = { 
 
    \t type: 'bar', 
 
    \t plot: { 
 
    \t _decimals: 4, 
 
    \t valueBox: {} 
 
    \t }, 
 
    \t tooltip: { 
 
    \t decimals: 4 
 
    \t }, 
 
\t series: [ 
 
\t \t { 
 
\t \t \t values: [35,42,67,89,25,34,67,85] 
 
\t \t } 
 
\t ] 
 
}; 
 

 
zingchart.render({ 
 
\t id: 'myChart', 
 
\t data: myConfig, 
 
\t height: '100%', 
 
\t width: '100%' 
 
});
html, body { 
 
\t height:100%; 
 
\t width:100%; 
 
\t margin:0; 
 
\t padding:0; 
 
} 
 
#myChart { 
 
\t height:100%; 
 
\t width:100%; 
 
\t min-height:150px; 
 
} 
 
.zc-ref { 
 
\t display:none; 
 
}
<!DOCTYPE html> 
 
<html> 
 
\t <head> 
 
\t <!--Assets will be injected here on compile. Use the assets button above--> 
 
\t \t <script src= "https://cdn.zingchart.com/zingchart.min.js"></script> 
 
\t <!--Inject End--> 
 
\t </head> 
 
\t <body> 
 
\t \t <div id="myChart"><a class="zc-ref" href="https://www.zingchart.com">Powered by ZingChart</a></div> 
 
\t </body> 
 
</html>