1
Google Chartsを使用するJSONからDataTableを作成し、いくつかの列を追加し、行を入力してから特定の列を選択するdatviewを作成します。Google Charts、DataViewは自分のDataTableのすべての列を見ることができません
GoogleのチャートAPIのdiplaysを実行すると:Invalid column index 6. Should be an integer in the range [0-4].
のDataTableがここ5.コードで、それに10列を持っていないので、これは、奇数です。ここで
function setoregonwkldbardata(){
var query = "SELECT Cluster, RAMCapacityGB, LHRAMCapacityGB, AvgVMRAMUsedGB, RAMUsedGB, NumVMs FROM clusterstat WHERE Location LIKE 'Oregon' AND Date = (SELECT MAX(Date) FROM clusterstat) ORDER BY Cluster ASC";
var urlencoded = encodeURI(sql2json+query);
var jsonData = $.ajax({
url: urlencoded,
dataType: "json",
async: false
}).responseText;
// assign a google DataTable object
wkldbardata = new google.visualization.DataTable(jsonData);
var numrows = wkldbardata.getNumberOfRows();
//column 6
wkldbardata.addColumn({
type: 'number',
role: 'data',
label: 'N1 RAM Workloads'
});
for (var i=0;i<numrows;i++){
var totcap = wkldbardata.getValue(i, 1);
var lhcap = wkldbardata.getValue(i,2);
var n1cap = totcap - lhcap;
var avgram = wkldbardata.getValue(i,3)
var n1wklds = (Math.round(100*(n1cap/avgram))/100);
wkldbardata.setValue(i, 6, n1wklds);
}
//column 7
wkldbardata.addColumn({
type: 'number',
role: 'data',
label: 'RAM Workloads Installed'
});
for(var i=0;i<numrows;i++){
var usedram = wkldbardata.getValue(i, 4);
var avgram = wkldbardata.getValue(i,3)
var wkldsinstalled = (Math.round(100*(usedram/avgram))/100);
wkldbardata.setValue(i,7,wkldsinstalled);
}
//column 8
wkldbardata.addColumn({
type: 'string',
role: 'annotation'
});
for(var i=0;i<numrows;i++){
var numhosts = wkldbardata.getValue(i, 5);
var annotation = numhosts+" Real VMs";
wkldbardata.setValue(i,8,annotation);
}
//column 9
wkldbardata.addColumn({
type: 'string',
role: 'style'
});
for(var i=0;i<numrows;i++){
var n1capacity = (wkldbardata.getValue(i,1) - wkldbardata.getValue(i,2));
var n1workloads = (n1capacity/wkldbardata.getValue(i,3));
if (n1workloads < wkldbardata.getValue(i,5)){
wkldbardata.setValue(i,9,highlightstyle);
}
}
console.log(oregonwkldbardata.getNumberOfColumns()); //returns 10
}
function setoregonwkldbarview(){
wkldbarview = new google.visualization.DataView(wkldbardata);
console.log(wkldbardata.getNumberOfColumns()); //returns 10
wkldbarview.setColumns([0,6,7,8,9]);
}
は、それが働いて得るために、起動アニメーションを無効にする必要がありました
{"cols":[{"label":"Cluster","type":"string"},{"label":"RAMCapacityGB","type":"number"},{"label":"LHRAMCapacityGB","type":"number"},{"label":"AvgVMRAMUsedGB","type":"number"},{"label":"RAMUsedGB","type":"number"},{"label":"NumVMs","type":"number"}],"rows":[{"c":[{"v":"Tier0-DL380-NWDC-01"},{"v":511.93},{"v":255.97},{"v":39.27},{"v":157.06},{"v":4}]},{"c":[{"v":"Tier1-C7000-NWDC-01"},{"v":8190.91},{"v":255.97},{"v":23.43},{"v":5130.25},{"v":219}]},{"c":[{"v":"Tier1-C7000-NWDC-02"},{"v":8190.91},{"v":255.97},{"v":26.31},{"v":5841.38},{"v":222}]},{"c":[{"v":"Tier1-C7000-NWDC-03"},{"v":13822.9},{"v":511.97},{"v":31.18},{"v":9166.82},{"v":294}]},{"c":[{"v":"Tier1-C7000-NWDC-04"},{"v":7807.42},{"v":511.97},{"v":149.67},{"v":2993.39},{"v":20}]},{"c":[{"v":"Tier1-C7000-NWDC-05"},{"v":8190.91},{"v":255.97},{"v":24.07},{"v":3104.79},{"v":129}]},{"c":[{"v":"Tier1-C7000-NWDC-06"},{"v":2559.66},{"v":255.97},{"v":28.22},{"v":56.44},{"v":2}]},{"c":[{"v":"Tier1-DL980-NWDC-01"},{"v":36863.81},{"v":2047.99},{"v":117.48},{"v":27959.56},{"v":238}]},{"c":[{"v":"Tier2-C7000-NWDC-01"},{"v":8190.99},{"v":255.97},{"v":8.72},{"v":6097.06},{"v":699}]},{"c":[{"v":"Tier2-C7000-NWDC-02"},{"v":6911.37},{"v":191.99},{"v":11.17},{"v":5216.65},{"v":467}]},{"c":[{"v":"Tier2-C7000-NWDC-03"},{"v":8190.91},{"v":255.97},{"v":8.63},{"v":5023.78},{"v":582}]},{"c":[{"v":"Tier2-C7000-NWDC-04"},{"v":16126.91},{"v":511.97},{"v":16.23},{"v":10079.51},{"v":621}]},{"c":[{"v":"Tier2-C7000-NWDC-05"},{"v":14334.91},{"v":511.97},{"v":16.83},{"v":8366.73},{"v":497}]},{"c":[{"v":"Tier2-C7000-NWDC-06"},{"v":1791.76},{"v":255.97},{"v":0},{"v":25.11},{"v":0}]},{"c":[{"v":"Tier2-C7000-NWDC-DMZ-01"},{"v":1535.94},{"v":191.99},{"v":8.71},{"v":539.98},{"v":62}]},{"c":[{"v":"Tier2-C7000-VDI-01"},{"v":14845.91},{"v":511.97},{"v":5.8},{"v":7435.21},{"v":1282}]},{"c":[{"v":"Tier2-C7000-VDI-02"},{"v":1535.81},{"v":511.97},{"v":8.91},{"v":374.02},{"v":42}]},{"c":[{"v":"Tier2-C7000-XEN-INFRA-01"},{"v":2047.86},{"v":511.97},{"v":8.36},{"v":401.46},{"v":48}]},{"c":[{"v":"Tier2-C7000-XENAPP-01"},{"v":6143.59},{"v":511.97},{"v":13.69},{"v":1053.75},{"v":77}]},{"c":[{"v":"Tier2-DL380-XEN-01"},{"v":1279.66},{"v":127.97},{"v":23.94},{"v":765.99},{"v":32}]},{"c":[{"v":"Tier2-UCS-DELPHIX-01"},{"v":2047.45},{"v":255.93},{"v":105.33},{"v":947.96},{"v":9}]},{"c":[{"v":"UCSPOC-EVCCluster"},{"v":3583.29},{"v":3071.55},{"v":12.77},{"v":51.09},{"v":4}]}]}