你好我有这个简单的例子,有2个数据系列和2个趋势。
我希望它们只有1个趋势线,平均值!这可能吗?
google.load('visualization', '1.1', {packages: ['corechart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['X', 'Y', 'Z'],
[0, 0, 2],
[1, 2, 4],
[2, 4, 5],
[3, 6, 8],
[4, 8, 10],
[5, 10, 12],
[6, 12, 14],
[7, 14, 16],
[8, 16, 18],
[9, 18, 20],
[10, 20, 22]
]);
var options = {
height: 500,
legend: 'none',
colors: ['#9575cd', '#33ac71'],
pointShape: 'diamond',
trendlines: {
0: {
color:'red',
type: 'linear',
pointsVisible: false
}
}
};
var chart = new google.visualization.ScatterChart(document.getElementById('chart'));
chart.draw(data, options);
}
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
答案 0 :(得分:0)
只需指定数据点如下:
var data = google.visualization.arrayToDataTable([
['X', 'Y'],
[0, 0],
[1, 2],
[2, 4],
[3, 6],
[4, 8],
[5, 10],
[6, 12],
[7, 14],
[8, 16],
[9, 18],
[10, 20],
[0, 2],
[1, 4],
[2, 5],
[3, 8],
[4, 10],
[5, 12],
[6, 14],
[7, 16],
[8, 18],
[9, 20],
[10, 22]
]);
但是你无法区分这两组数据点! 如果您的目标是获得平均最佳拟合线,那么它将起作用。 :)