我有散點圖,繪製了所有點並繪製了平均點。我需要的是繪製散點圖中平均點的x軸和y軸。可能嗎?以下是我的代碼片段。是否可以繪製x軸和y軸作爲谷歌散點圖中平均點的線
CODE:
function drawChart(paramObj)
{
if (paramObj == 'undefined') {
alert('Something wrong with configuration');
return false;
}
var data = new google.visualization.DataTable();
var addRows = new Array();
var chart = null;
var headers = null;
jQuery.each(paramObj.dataArray.split('\n'), function (index, value) {
var tabs = value.split('\t');
if (tabs.length != 7) {
return;
}
if (index != undefined && index == 0) {
headers = tabs;
data.addColumn('number', dfv(1, headers, ''));
data.addColumn('number', dfv(2, headers, ''));
} else {
var name = dfv(0, tabs, '');
var xval = parseFloat(parseFloat(dfv(1, tabs, '')).toFixed(2));
var yval = parseFloat(parseFloat(dfv(2, tabs, '')).toFixed(2));
var xval_ori = parseFloat(parseFloat(dfv(3, tabs, '')).toFixed(2));
var yval_ori = parseFloat(parseFloat(dfv(4, tabs, '')).toFixed(2));
var opt1_val = dfv(5, tabs, '');
var opt2_val = dfv(6, tabs, '');
if (name == 'Average') {
var test = [
xval,yval,
name + '\n' +
dfv(3,headers,'') + ' = ' + xval_ori + ' ' +
dfv(4,headers,'') + ' = ' + yval_ori + '\n' +
((opt1_val != ' ') ? dfv(5,headers,'') + ' = ' + opt1_val : '') + ' ' +
((opt2_val != ' ') ? dfv(6,headers,'') + ' = ' + opt2_val : ''),
'point { size: 4; shape-type: circle; fill-color: red; }'
];
} else {
var test = [
xval,yval,
name + '\n' +
dfv(3,headers,'') + ' = ' + xval_ori + ' ' +
dfv(4,headers,'') + ' = ' + yval_ori + '\n' +
((opt1_val != ' ') ? dfv(5,headers,'') + ' = ' + opt1_val : '') + ' ' +
((opt2_val != ' ') ? dfv(6,headers,'') + ' = ' + opt2_val : ''),
null
];
}
addRows.push(test);
}
});
data.addColumn({type: 'string', role: 'tooltip'});
data.addColumn({type: 'string', role: 'style'});
data.addRows(addRows);
var options = {
title: dov('title', paramObj, '(no title)'),
hAxis: {title: dov('xLabel', paramObj, '')},
vAxis: {title: dov('yLabel', paramObj, '')},
legend: dov('legend', paramObj, 'none'),
width: dov('width', paramObj, 1200),
height: dov('height', paramObj, 800),
chartArea: {left:100,top:50,right:100,bottom:50}
};
switch (dov('graphType', paramObj, 'scatter')) {
case 'scatter':
chart = new google.visualization.ScatterChart(document.getElementById(dov('container_id', paramObj, 'container')));
break;
default:
break;
}
if (chart) {
chart.draw(data, options);
return true;
}
return false;
}
聽起來像你只需要添加另一列,對於平均_series _...的 – WhiteHat
@WhiteHat遺憾也許是我的問題是缺少一個詞圖x軸和y軸「作爲一條線」。我已經用單獨的顏色繪製了平均值,但現在我需要繪製一條連接該平均點的線。 – Wolverine
@WhiteHat編輯我的問題與圖像有一個想法我正在做什麼來實現 – Wolverine