2017-04-20 32 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>