Google线图,删除多余的线
我是Google Graphs中的新成员,我试图在 以下的照片(预计)中生成此图,但我得到的图有点不同。我有三个不同的字母,每个字母包含自己的值(A1,A2,A3,B1,B2 ...例如)。Google线图,删除多余的线
有我正努力代码:
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('date', 'Date');
data.addColumn('string', 'Type');
data.addColumn('number', 'Value');
data.addRows([
[new Date(2014, 0, 30), 'A', 75],
[new Date(2014, 0, 30), 'A', 100],
[new Date(2014, 0, 30), 'A', 125],
[new Date(2014, 0, 31), 'A', 75],
[new Date(2014, 0, 31), 'A', 100],
[new Date(2014, 0, 31), 'A', 125],
[new Date(2014, 0, 30), 'B', 150],
[new Date(2014, 0, 30), 'B', 175],
[new Date(2014, 0, 30), 'B', 200],
[new Date(2014, 0, 31), 'B', 150],
[new Date(2014, 0, 31), 'B', 175],
[new Date(2014, 0, 31), 'B', 200],
]);
var view = new google.visualization.DataView(data);
view.setColumns([0, {
type: 'number',
label: 'A',
calc: function (dt, row) {
return (dt.getValue(row, 1) == 'A') ? dt.getValue(row, 2) : null;
}
}, {
type: 'number',
label: 'B',
calc: function (dt, row) {
return (dt.getValue(row, 1) == 'B') ? dt.getValue(row, 2) : null;
}
}, {
type: 'number',
label: 'C',
calc: function (dt, row) {
return (dt.getValue(row, 1) == 'C') ? dt.getValue(row, 2) : null;
}
}, 2]);
var chart = new google.visualization.LineChart(document.querySelector('#chart_div'));
chart.draw(view, {
height: 400,
width: 600,
hAxis: {
format: 'dd.MM.yyyy',
minValue: new Date(2014, 0, 29, 12),
maxValue: new Date(2014, 0, 31, 10)
},
series: {
0: {
// series A options
pointSize: 5,
lineWidth: 0
},
3: {
// this series draws the line
pointSize: 0,
lineWidth: 1,
visibleInLegend: false,
enableInteractivity: false,
color:'blue'
}
}
});
}
google.load('visualization', '1', {packages: ['corechart'], callback: drawChart});
而且它显示了我这一点,我不知道如何在2014年1月31日删除订单 - > A3与30.01.2014-> B1和颜色蓝线为蓝色线,红线线为红色线可以吗? :
但预计一个低于:
这就是我的回答对你previous question不是拿这个最好的办法的情况下,但有一个简单的解决方案来修改您的现有代码以完成此项工作。从传递给view.setColumns
数组的末尾删除2
:
view.setColumns([0, {
type: 'number',
label: 'A',
calc: function (dt, row) {
return (dt.getValue(row, 1) == 'A') ? dt.getValue(row, 2) : null;
}
}, {
type: 'number',
label: 'B',
calc: function (dt, row) {
return (dt.getValue(row, 1) == 'B') ? dt.getValue(row, 2) : null;
}
}, {
type: 'number',
label: 'C',
calc: function (dt, row) {
return (dt.getValue(row, 1) == 'C') ? dt.getValue(row, 2) : null;
}
}]);
并调整一系列选项:
series: {
0: {
// series A options
pointSize: 5,
lineWidth: 1
},
1: {
// series B options
pointSize: 5,
lineWidth: 1
},
2: {
// series C options
pointSize: 5,
lineWidth: 1
}
}
asgallant非常感谢你的工作!现在我需要将它实现到我的项目中,我需要生成json并通过“DataTable”提供这些数据什么是PHP数组中的数据结构?正如我问我以前的问题,我给了一个示例php数组。例如 –
我的意思是[cols]和[rows]格式 –
您是问一般的结构是什么,或者如何专门复制DataTable? – asgallant
请分享你已经尝试了代码,为什么它不工作。 – jmac
jmac我添加了我正在尝试的代码,如果你能帮助我会更好。谢谢 –
难以产生吗? –