Oops, typo. The bind statement should be:
dashboard.bind([control], [chart]);
On Wednesday, May 21, 2014 1:43:26 PM UTC-4, Andrew Gallant wrote:
>
> The ChartRangeFilter doesn't care where you get your data from. First,
> you need to convert your chart from a chart object to a ChartWrapper
> object. This code:
>
> var options = {
> theme: 'maximized'
> };
>
> var chart = new
> google.visualization.LineChart(document.getElementById('chart_div'));
> chart.draw(data, options);
>
> becomes this:
>
> var chart = new google.visualization.ChartWrapper({
> chartType: 'LineChart',
> containerId: 'chart_div',
> options: {
> // options for the chart - I'll go over recommendations for these
> below
> theme: 'maximized'
> }
> });
>
> Then, you need to create a ControlWrapper for the ChartRangeFilter:
>
> var control = new google.visualization.ControlWrapper({
> controlType: 'ChartRangeFilter',
> containerId: 'control_div',
> options: {
> filterColumnIndex: 0, set the column index to filter on here
> ui: {
> chartOptions: {
> // options for the chart inside the filter - I'll go over
> recommendations for these below
> }
> }
> }
> });
>
> Then create a Dashboard object, bind the control to the chart, and draw
> the Dashboard:
>
> var dashboard = new
> google.visualization.Dashboard(document.querySelector('#dashboard'));
> dashboard.bind([control[, [chart]);
> dashboard.draw(data);
>
> In your HTML, you need to add a div for the control and a div for the
> dashboard that wraps the control and chart:
>
> <div id="dashboard">
> <div id="chart_div" style="width: 850px; height: 500px;"></div>
> <div id="control_div" style="width: 850px; height: 50px;"></div>
> </div>
>
> Typically, most users set the width of the chart and control to the same
> value. You can either do this via styling the divs or via the chart's
> "width" and control's "ui.chartOptions.width" options (I styled the divs
> here, since that's what your original code does). To align the chart and
> control further, you need to set the chartArea.left and chartArea.width
> options for the chart and the control's internal chart. These values can
> either be a number (pixels) or a string (percent of the total width). Set
> the to the same values for both the chart and control to make them align.
> If there is a large gap between the chart and control, you can narrow that
> by setting the chartArea.top and chartArea.height options on the chart.
>
> var chart = new google.visualization.ChartWrapper({
> chartType: 'LineChart',
> containerId: 'chart_div',
> options: {
> chartArea: {
> left: '10%',
> width: '65%',
> top: '10%',
> height: '80%'
> },
> theme: 'maximized'
> }
> });
>
> var control = new google.visualization.ControlWrapper({
> controlType: 'ChartRangeFilter',
> containerId: 'control_div',
> options: {
> filterColumnIndex: 0, // set the column index to filter on here
> ui: {
> chartOptions: {
> chartArea: {
> left: '10%',
> width: '65%'
> }
> }
> }
> }
> });
>
> Other options are covered in the ChartRangeFilter
> documentation<https://developers.google.com/chart/interactive/docs/gallery/controls#chartrangefilter>
> .
>
> On Wednesday, May 21, 2014 11:40:45 AM UTC-4, Joey D'Anna wrote:
>>
>> Sorry - i meant chartrangefilter not range select
>>
>> On Wednesday, May 21, 2014 11:39:54 AM UTC-4, Joey D'Anna wrote:
>>>
>>> Hi guys - I have a site that uses a php script to feed JSON data to a
>>> google line chart.
>>> I would love to retrofit it to use the new ChartRangeFinder control so i
>>> can zoom in and out of the chart, but I dont really know javascript very
>>> well so im not sure how to go about it.
>>>
>>> Right now here is my javascript code:
>>>
>>> <script type="text/javascript">
>>>
>>> $.ajaxSetup ({
>>>
>>> // Disable caching of AJAX responses */
>>>
>>> cache: false
>>>
>>> });
>>>
>>> google.load("visualization", "1", { packages: ["corechart"] });
>>>
>>> google.setOnLoadCallback(drawChart);
>>>
>>> function drawChart() {
>>>
>>> var jsonData = $.ajax({
>>>
>>> url: "chartselect.php?limit=<?php echo $limit;?>&s1=<?php
>>> echo $s1;?>&s2=<?php echo $s2;?>&s3=<?php echo $s3;?>&s4=<?php echo
>>> $s4;?>&s5=<?php echo $s5?>&s6=<?php echo $s6?>",
>>>
>>> dataType: "json",
>>>
>>> async: false
>>>
>>> }).responseText;
>>>
>>> var obj = jQuery.parseJSON(jsonData);
>>>
>>> var data = google.visualization.arrayToDataTable(obj);
>>>
>>> var options = {
>>>
>>> theme: 'maximized'
>>>
>>> };
>>>
>>> var chart = new
>>> google.visualization.LineChart(document.getElementById('chart_div'));
>>>
>>> chart.draw(data, options);
>>>
>>> }
>>>
>>> function refreshChart() {
>>>
>>> setInterval(function() { drawChart() }, 60000);
>>>
>>> };
>>>
>>> $(document).ready(function() {
>>>
>>> refreshChart();
>>>
>>> });
>>>
>>> </script>
>>>
>>>
>>>
>>> and in the HTML i have a div for the chart:
>>> <div id="chart_div" style="width: 850px; height: 500px;"></div>
>>>
>>>
>>> Is there an easy way to add the RangeSelect to this? I haven't been able
>>> to find an example of one where it pulls JSON data from another php page
>>> yet.
>>> thanks
>>>
>>>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.