散点图 google 图表 - Y 轴中的字符串值

Scatter google chart - string values in Y axis

从昨天开始,我尝试用 google 图表绘制图表。我有一个问题。我试图将字符串放在 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>