1 google.load('visualization', '1', {'packages' : ['controls','table','corechart','geochart']});
3 function renderChart(newStyle, dialog, container, dataSourceUrl, yColumn, xColumn, aggFunc, options) {
5 $(dialog).dialog("open");
9 $(dialog).modal('show');
10 $('.modal-body').scrollTop(0);
13 startQuery(container, dataSourceUrl, yColumn, xColumn, aggFunc, options)
16 function startQuery(container, dataSourceUrl, yColumn, xColumn, aggFunc, options) {
17 var query = new google.visualization.Query(dataSourceUrl);
18 query && query.abort();
19 query.send(function(response) {handleResponse_psg(container, dataSourceUrl, response, yColumn, xColumn, aggFunc, options);});
22 // NOTE: appended _psg to showLine() and handleResponse() to prevent conflict
23 // with Sapan's analytics page.
25 function agg_bandwidth(arr) {
27 for (var i = 0; i < arr.length; i++) {
28 ret+=arr[i]*8.0/1024.0/1024.0/1024.0;
33 function showLine_psg(container, dt, options) {
39 'backgroundColor': 'transparent',
40 'titleTextStyle': {"color": "black"},
42 'hAxis': {"baselineColor": "darkBlue",
43 "textStyle": {"color": "black"}},
44 'vAxis': {"baselineColor": "darkBlue",
45 "textStyle": {"color": "black"}},
48 options = $.extend(true, {}, base_options, options);
50 var lineChart = new google.visualization.ChartWrapper({
51 'chartType': 'LineChart',
52 'containerId': container.substring(1),
53 'view': {'columns': [0, 1]},
56 lineChart.setDataTable(dt);
61 function fixDate(unixDate) {
62 return new Date(unixDate*1000);
65 function fixDate2(unixDate) {
66 return new Date(unixDate);
69 function handleResponse_psg(container, dataSourceUrl, response, yColumn, xColumn, aggFunc, options) {
70 var supportedClasses = {
71 'Table':google.visualization.Table,
72 'LineChart':google.visualization.LineChart,
73 'ScatterChart':google.visualization.ScatterChart,
74 'ColumnChart':google.visualization.ColumnChart,
75 'GeoChart':google.visualization.GeoChart,
76 'PieChart':google.visualization.PieChart,
77 'Histogram':google.visualization.Histogram};
79 if (response.isError()) {
80 //console.log("retry chart");
81 setTimeout(function () { startQuery(container, dataSourceUrl, yColumn, xColumn, aggFunc, options) }, 5000);
85 var proxy = new google.visualization.ChartWrapper({
87 'containerId': 'graph_work',
96 'view': {'columns': [0,1]}
99 google.visualization.events.addListener(proxy, 'ready', function () {
100 var dt = proxy.getDataTable();
101 var groupedData1 = google.visualization.data.group(dt, [{
109 label: dt.getColumnLabel(xColumn),
110 aggregation: aggFunc}]);
112 showLine_psg(container, groupedData1, options);
115 proxy.setDataTable(response.getDataTable());