我使用谷歌gannt图表。我已经填充了json数据中的数据,但我的问题是如何动态更改每个图表的颜色?或每种数据的图表的不同颜色。
继承我的代码
var pathArray = window.location.pathname.split( '/' );
var project_id = pathArray[3];
google.charts.load('current', {'packages':['gantt']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
$.ajax({
url: '/admin/milestone/project/pmt/api/' + project_id,
dataType: 'json',
success: function (jsonData) {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Task ID');
data.addColumn('string', 'Task Name');
data.addColumn('string', 'Resource');
data.addColumn('date', 'Start Date');
data.addColumn('date', 'End Date');
data.addColumn('number', 'Duration');
data.addColumn('number', 'Percent Complete');
data.addColumn('string', 'Dependencies');
for(var i = 0; i < jsonData.length; i++) {
data.addRows([
[jsonData[i]._id, jsonData[i].subject, jsonData[i].status,
new Date(jsonData[i].kick_off), new Date(jsonData[i].due_date), null, 100, null]
]);
}
var options = {
height: 400,
gantt: {
trackHeight: 30
}
};
var chart = new google.visualization.Gantt(document.getElementById('chart_div'));
chart.draw(data, options);
}
});
}
感谢