简体   繁体   English

Google图表:如何在新的Material图表中使用仪表板?

[英]Google charts: How to use dashboard with new Material charts?

It seems dashboard is only using the old way to load its library the way "Classic charts" use to. 似乎仪表板仅使用“经典图表”所使用的旧方法来加载其库。 How can I get a dashboard to work with the new "Material" google charts? 我如何获得一个仪表板来使用新的“材料”谷歌图表? Specifically the line graph 具体来说就是折线图

Material chart jsfiddle: https://jsfiddle.net/yzhsf1gv/3/ 材质表jsfiddle: https ://jsfiddle.net/yzhsf1gv/3/

Dashboard jsiddle: https://jsfiddle.net/job30vwy/ 仪表板jsiddle: https ://jsfiddle.net/job30vwy/

My native guess was 我的原生猜测是

  google.charts.load('current', {'packages': ['line', 'controls']});

but that doesnt seem to work 但这似乎不起作用

seems to work here...? 似乎在这里工作...?

just specify material chart in ChartWrapper chartType ... 只需在ChartWrapper chartType指定材料图表chartType

'chartType': 'Line',

vs.

'chartType': 'LineChart',

use the same class name as you would specify here --> 使用与您在此处指定的相同的类名->

new google.charts.-->Line(document.getElementById('chart_div'))

from fiddle fork 小提琴叉

 google.charts.load('current', {'packages':['line', 'controls']}); google.charts.setOnLoadCallback(drawStuff); function drawStuff() { var dashboard = new google.visualization.Dashboard( document.getElementById('programmatic_dashboard_div')); // We omit "var" so that programmaticSlider is visible to changeRange. programmaticSlider = new google.visualization.ControlWrapper({ 'controlType': 'NumberRangeFilter', 'containerId': 'programmatic_control_div', 'options': { 'filterColumnLabel': 'Donuts eaten', 'ui': {'labelStacking': 'vertical'} } }); programmaticChart = new google.visualization.ChartWrapper({ 'chartType': 'Line', 'containerId': 'programmatic_chart_div', 'options': { 'width': 300, 'height': 300, 'legend': 'none', 'chartArea': {'left': 15, 'top': 15, 'right': 0, 'bottom': 0}, 'pieSliceText': 'value' } }); var data = google.visualization.arrayToDataTable([ ['Name', 'Donuts eaten'], ['Michael' , 5], ['Elisa', 7], ['Robert', 3], ['John', 2], ['Jessica', 6], ['Aaron', 1], ['Margareth', 8] ]); dashboard.bind(programmaticSlider, programmaticChart); dashboard.draw(data); } 
 <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <div id="programmatic_dashboard_div" style="border: 1px solid #ccc"> <table class="columns"> <tr> <td> <div id="programmatic_control_div" style="padding-left: 2em; min-width: 250px"></div> <div> <button style="margin: 1em 1em 1em 2em" onclick="changeRange();"> Select range [2, 5] </button><br /> <button style="margin: 1em 1em 1em 2em" onclick="changeOptions();"> Make the pie chart 3D </button> </div> <script type="text/javascript"> function changeRange() { programmaticSlider.setState({'lowValue': 2, 'highValue': 5}); programmaticSlider.draw(); } function changeOptions() { programmaticChart.setOption('is3D', true); programmaticChart.draw(); } </script> </td> <td> <div id="programmatic_chart_div"></div> </td> </tr> </table> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM