gpt4 book ai didi

axis-labels - 在 Dygraphs 中,如何将 AxisLabels 显示为文本而不是数字/日期

转载 作者:行者123 更新时间:2023-12-04 02:39:16 27 4
gpt4 key购买 nike

我需要构建一个图表来按地区显示世界的人口,示例数据是

China           1,361,300,000
India 1,236,970,000
United States 317,148,000
Indonesia 237,641,326
Brazil 201,032,714

我是 Dygraphs 的新手,我尝试了同样的简单示例:

<html>
<head>
<script type="text/javascript"
src="http://dygraphs.com/dygraph-combined.js"></script>

</head>
<body>
<div id="demodiv" style="width:500px;height:500px"></div>
<script type="text/javascript">
var data = "Country,Population\n" +
"1,1361300000\n" +
"2,1236970000\n" +
"3,317148000\n" +
"4,237641326\n" +
"5,201032714\n";
g = new Dygraph(document.getElementById("demodiv"), data, {
title: "World's Population"
});
</script>
</body>
</html>

现在,如何使用 Dygraphsx 轴 上显示国家名称而不是数字? Dygraphs 是否可行?

提前致谢。

最佳答案

您可以使用 valueFormatter 和 axisLabelFormatter 选项。参见 http://dygraphs.com/options.html

以下示例将打印图例内的“文本:”和数据中的 x 值。

axes: {
x: {
valueFormatter: function(x) {
return 'text';
},
axisLabelFormatter: function(x) {
return x;
},
}
},

jsfiddle 中的示例:http://jsfiddle.net/JaM3S/

关于axis-labels - 在 Dygraphs 中,如何将 AxisLabels 显示为文本而不是数字/日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20234787/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com