答案 0 :(得分:1)
使用ComboChart两个系列 - 散点图和线
只需要两者的数据,使用行不匹配的null
请参阅以下工作代码段...
google.charts.load('current', {
callback: function () {
var dataTable = new google.visualization.DataTable({
cols: [
{label: 'X', type: 'number'},
{label: 'Y', type: 'number'},
{label: 'Line', type: 'number'},
],
rows: [
{c:[{v: 3}, {v: 3.5}, null]},
{c:[{v: 4}, {v: 5.5}, null]},
{c:[{v: 4}, {v: 5}, null]},
{c:[{v: 6.5}, {v: 7}, null]},
{c:[{v: 8}, {v: 12}, null]},
{c:[{v: 11}, {v: 14}, null]},
// add line
{c:[{v: 0}, null, {v: 0}]},
{c:[{v: 20}, null, {v: 20}]},
]
});
var options = {
legend: 'none',
hAxis: {
ticks: [0, 5, 10, 15, 20]
},
height: 400,
series: {
// line
1: {
type: 'line',
visibleInLegend: false
},
},
seriesType: 'scatter',
vAxis: {
ticks: [0, 5, 10, 15, 20]
}
};
var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
chart.draw(dataTable, options);
},
packages:['corechart']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>