本文介绍了使用 ChartEditor 调整 google 可视化的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用google可视化ChartEditor时是否可以设置图表的宽度和高度?
我要求图表为页面宽度的 100%,然后以像素为单位设置高度,目前当我在选项中设置宽度和高度时,它们会被忽略.
到目前为止我已经完成的代码如下:
该图表还包含一个与仪表板链接的 CategoryFilter,需要使用所显示的图表.
当前,当图表呈现时,它相当小.
解决方案
这样的事情应该可行,我切换了数据并修改了滑块以使代码段起作用.
google.load("visualization", "1", {包:["corechart", "controls", "charteditor"] });google.setOnLoadCallback(loadEditor);window.addEventListener('resize', redrawChart, false);var 图表编辑器;无功数据;无功仪表板;var rangeSlider;var 包装器;函数加载编辑器(){数据 = google.visualization.arrayToDataTable([['元素','密度'],['铜',8.94],['白银',10.49],['黄金',19.30],['白金',21.45]]);仪表板 = 新的 google.visualization.Dashboard(document.getElementById('dashboard_div'));rangeSlider = 新的 google.visualization.ControlWrapper({'controlType': '类别过滤器','containerId': 'filter_div','选项': {'filterColumnLabel': '密度',用户界面":{'标签':'密度'}}});包装器 = 新的 google.visualization.ChartWrapper({chartType: 'ColumnChart',容器 ID: 'chart_div',数据表:数据});chartEditor = 新的 google.visualization.ChartEditor();google.visualization.events.addListener(chartEditor, 'ok', drawChart);chartEditor.openDialog(wrapper, {});}函数 drawChart() {包装器 = chartEditor.getChartWrapper();重绘图表();}函数重绘图表(){变量高度;可变宽度;高度 = '200px';width = Math.min(document.documentElement.clientWidth, window.innerWidth || 0) + 'px';wrapper.setOption('height', height);wrapper.setOption('width', width);仪表板绑定(范围滑块,包装器);仪表板.绘制(数据);}
<script src="https://www.google.com/jsapi"></script><div id="dashboard_div"><div id="filter_div"></div><div id="chart_div"></div>
is it possible to set the width and height of a chart when using the google visualization ChartEditor?
I require the chart to be 100% the width of the page and then set the height in pixels, currently when I set the width and height in the options they are being ignored.
the code that I have worked on so far is below:
<script type="text/javascript">
google.load("visualization", "1", { packages: ["corechart", "controls", "charteditor"] });
google.setOnLoadCallback(loadEditor);
var chartEditor = null;
window.onresize = function() {
loadEditor();
};
function loadEditor() {
var data = google.visualization.arrayToDataTable([@Html.Raw(@ViewBag.ChartData)]);
var dashboard = new google.visualization.Dashboard(document.getElementById('dashboard_div'));
var rangeSlider = new google.visualization.ControlWrapper({
'controlType': 'CategoryFilter',
'containerId': 'filter_div',
'options': {
'filterColumnLabel': 'VAR1',
'ui': {
'label': 'Years'
}
}
});
var wrapper = new google.visualization.ChartWrapper({
chartType: 'ColumnChart',
containerId: 'chart_div',
dataTable: data
});
chartEditor = new google.visualization.ChartEditor();
google.visualization.events.addListener(chartEditor, 'ok', redrawChart);
chartEditor.openDialog(wrapper, {});
dashboard.bind(rangeSlider, wrapper);
dashboard.draw(data);
}
function redrawChart() {
chartEditor.getChartWrapper().draw(document.getElementById('chart_div'));
}
</script>
the chart also incorporates a CategoryFilter linked with a dashboard is required to work with the chart displayed.
Currently when the chart is rendered it is fairly small.
解决方案
Something like this should work, I switched out the data and modified the slider to get the snippet to work.
google.load("visualization", "1", { packages: ["corechart", "controls", "charteditor"] });
google.setOnLoadCallback(loadEditor);
window.addEventListener('resize', redrawChart, false);
var chartEditor;
var data;
var dashboard;
var rangeSlider;
var wrapper;
function loadEditor() {
data = google.visualization.arrayToDataTable([
['Element', 'Density'],
['Copper', 8.94],
['Silver', 10.49],
['Gold', 19.30],
['Platinum', 21.45]
]);
dashboard = new google.visualization.Dashboard(document.getElementById('dashboard_div'));
rangeSlider = new google.visualization.ControlWrapper({
'controlType': 'CategoryFilter',
'containerId': 'filter_div',
'options': {
'filterColumnLabel': 'Density',
'ui': {
'label': 'Density'
}
}
});
wrapper = new google.visualization.ChartWrapper({
chartType: 'ColumnChart',
containerId: 'chart_div',
dataTable: data
});
chartEditor = new google.visualization.ChartEditor();
google.visualization.events.addListener(chartEditor, 'ok', drawChart);
chartEditor.openDialog(wrapper, {});
}
function drawChart() {
wrapper = chartEditor.getChartWrapper();
redrawChart();
}
function redrawChart() {
var height;
var width;
height = '200px';
width = Math.min(document.documentElement.clientWidth, window.innerWidth || 0) + 'px';
wrapper.setOption('height', height);
wrapper.setOption('width', width);
dashboard.bind(rangeSlider, wrapper);
dashboard.draw(data);
}
<script src="https://www.google.com/jsapi"></script>
<div id="dashboard_div">
<div id="filter_div"></div>
<div id="chart_div"></div>
</div>
这篇关于使用 ChartEditor 调整 google 可视化的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!