【问题标题】:How to format numbers on tooltips with ZingChart如何使用 ZingChart 格式化工具提示上的数字
【发布时间】:2017-04-20 07:41:31
【问题描述】:

我想像这样格式化工具提示上显示的数字:

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

我检查了documentation,但它主要处理日期和大数字

有没有办法做到这一点?

【问题讨论】:

    标签: javascript charts zingchart


    【解决方案1】:

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

     plot: {
      decimals: 4,
      valueBox: {
    
      }
    }...
    

    如果您仅在工具提示对象内执行此操作,您将只会获得应用于工具提示的截断值。

    注意:JSON 属性前面的下划线类似于内联注释。

    plot docs here

    var myConfig = {
     	type: 'bar', 
     	plot: {
     	  _decimals: 4,
     	  valueBox: {}
     	},
     	tooltip: {
     	  decimals: 4
     	},
    	series: [
    		{
    			values: [35,42,67,89,25,34,67,85]
    		}
    	]
    };
    
    zingchart.render({ 
    	id: 'myChart', 
    	data: myConfig, 
    	height: '100%', 
    	width: '100%' 
    });
    html, body {
    	height:100%;
    	width:100%;
    	margin:0;
    	padding:0;
    }
    #myChart {
    	height:100%;
    	width:100%;
    	min-height:150px;
    }
    .zc-ref {
    	display:none;
    }
    <!DOCTYPE html>
    <html>
    	<head>
    	<!--Assets will be injected here on compile. Use the assets button above-->
    		<script src= "https://cdn.zingchart.com/zingchart.min.js"></script>
    	<!--Inject End-->
    	</head>
    	<body>
    		<div id="myChart"><a class="zc-ref" href="https://www.zingchart.com">Powered by ZingChart</a></div>
    	</body>
    </html>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-16
      • 1970-01-01
      • 1970-01-01
      • 2018-12-07
      相关资源
      最近更新 更多