gpt4 book ai didi

javascript - 谷歌散点图 - Y 轴中的字符串值

转载 作者:行者123 更新时间:2023-11-30 12:16:54 25 4
gpt4 key购买 nike

从昨天开始,我尝试用谷歌图表绘制图表。我有一个问题。我试图将字符串放在 Y 轴上,但脚本没有显示任何内容。

我试着用代码来做到这一点:

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('visualization', '1.1', {packages: ['scatter']});
google.setOnLoadCallback(drawChart);

function drawChart () {

var data = new google.visualization.DataTable();
data.addColumn('number', 'document');
data.addColumn('string', 'term');

data.addRows([
[1 , 'word1'] , [3 , 'word2']
]);
var options = {
width: 900,
height: 500,
chart: {
title: 'weight of terms'
},
axes: {
x: {
0: {side: 'bottom'}
}
}
};

var chart = new google.charts.Scatter(document.getElementById('scatter_top_x'));


chart.draw(data, google.charts.Scatter.convertOptions(options));
}
</script>

这给了我一个结果:http://darium.linuxpl.eu/chart/

目标:我想像这样画点什么-

https://www.imageupload.co.uk/images/2015/08/25/asd.png

有没有办法画出我想要的东西?

最佳答案

Data column(s) for axis #0 cannot be of type string

所以你需要改变坐标轴,

google.load('visualization', '1.1', {packages: ['scatter']});
google.setOnLoadCallback(drawChart);

function drawChart () {

var data = new google.visualization.DataTable();
data.addColumn('string', 'term');
data.addColumn('number', 'document');

data.addRows([
['word1', 1] , ['word2', 3]
]);

var options = {
width: 900,
height: 500,
chart: {
title: 'weight of terms'
},
axes: {
x: {
0: {side: 'bottom'}
}
}
};

var chart = new google.charts.Scatter(document.getElementById('scatter_top_x'));

chart.draw(data, google.charts.Scatter.convertOptions(options));
}
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<div id="scatter_top_x"></div>

关于javascript - 谷歌散点图 - Y 轴中的字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32197733/

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