Json Google图表,隐藏列的显示,但保留基础数据以供使用
在以下JSON中:Json Google图表,隐藏列的显示,但保留基础数据以供使用,json,google-visualization,Json,Google Visualization,在以下JSON中: var data = new google.visualization.DataTable( { cols: [{id: 'Option1', label: 'Manufacturer', type: 'string'}, {id: 'Option2', label: 'Region', type: 'string'}, {id: 'Op
var data = new google.visualization.DataTable(
{
cols: [{id: 'Option1', label: 'Manufacturer', type: 'string'},
{id: 'Option2', label: 'Region', type: 'string'},
{id: 'Option3', label: 'Option3', type: 'number'},
{id: 'Option4', label: 'Option4', type: 'number'},
{id: 'Option5', label: 'Option5', type: 'number'},
{id: 'Option6', label: 'Option6', type: 'number'},
{id: 'Option7', label: 'Option7', type: 'number'},
{id: 'Option8', label: 'Option8', type: 'number'}],
rows: [{c:[{v: 'Ford'}, {v: 'South East'}, {v: 2}, {v: 3}, {v: 4}, {v: 5}, {v: 6}, {v: 7}]},
{c:[{v: 'Ford'}, {v: 'South East'}, {v: 2}, {v: 3}, {v: 4}, {v: 5}, {v: 6}, {v: 7}]},
{c:[{v: 'Ford'}, {v: 'South East'}, {v: 2}, {v: 3}, {v: 4}, {v: 5}, {v: 6}, {v: 7}]},
{c:[{v: 'BMW'}, {v: 'South East'}, {v: 2}, {v: 3}, {v: 4}, {v: 5}, {v: 6}, {v: 7}]},
{c:[{v: 'BMW'}, {v: 'North'}, {v: 2}, {v: 3}, {v: 4}, {v: 5}, {v: 6}, {v: 7}]},
{c:[{v: 'BMW'}, {v: 'North'}, {v: 2}, {v: 3}, {v: 4}, {v: 5}, {v: 6}, {v: 7}]},
{c:[{v: 'Citroen'}, {v: 'North'}, {v: 2}, {v: 3}, {v: 4}, {v: 5}, {v: 6}, {v: 7}]},
{c:[{v: 'Citroen'}, {v: 'South East'}, {v: 2}, {v: 3}, {v: 4}, {v: 5}, {v: 6}, {v: 7}]}
]
},
0.6
)
我的图表“将”以行的形式显示制造商,每行有7条数据
我希望能够使用依赖控件过滤数据,以便只查看每个区域中的行(列1)
由于区域列不是整数,因此无法显示,因此当前无法绘制此图形
因此,我希望“隐藏”区域列,使其不显示为条形,但可用于从属控件
我找不到任何方法,有人能帮我吗?我认为hideColumns方法不起作用,因为它会从数据对象中删除列,因此依赖控件无法看到它。解决方案是使用“视图”
// Create a bar chart, passing some options
barChart = new google.visualization.ChartWrapper({
'chartType': 'BarChart',
'containerId': 'chart_div',
'options': {
'width': '100%',
'height': '120%',
'vAxis': {title: "Branch"},
'hAxis': {title: "Cups"},
'fontSize': 14,
'showRowNumber' : true,
},
'view': {'columns': [0,2,3,4,5,6,7]}
});
希望这能帮助其他有同样问题的人。您也可以通过使用上述代码执行以下操作来直接使用dataView
function hideColumns (chart, data, options, colToHide) {
dataview = new google.visualization.DataView(data);
dataview.hideColumns(colToHide);
// you can also use dataview.setColumns([1,2]) to show only selected columns and hide the rest
chart.draw(dataview, options)
};