Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zoom Google Line chart

I am trying to create a line chart with the Google Visualization API. I want to enable zooming. Documents say that the 'explorer' option is useful. But when I try to use the 'explorer' option, the chart is shown but zoom does not work.

This is my code:

function drawVisualization(dataValues) {
var data = new window.google.visualization.DataTable();
data.addColumn('date', 'Date');
data.addColumn('number', 'Count');

for (var i = 0; i < dataValues.length; i++) {
    data.addRow([new Date(dataValues[i].Year, dataValues[i].Month-1, dataValues[i].Day), dataValues[i].Count]);
}

var formatter_short = new google.visualization.DateFormat({ formatType: 'short' });
formatter_short.format(data, 0);
var options = {
    title: "Time statistics",
    explorer: { maxZoomOut: 8 }
};
var chart = new google.visualization.LineChart(document.getElementById('date'));
chart.draw(data, options);
}

How can I resolve this problem and make a line chart zoomable?

like image 460
alinaish Avatar asked Dec 24 '13 16:12

alinaish


People also ask

How do you zoom in on a line graph?

You can zoom in on the graph by resetting the scale on the y-axis. Double-click on the y-axis and a Format Axis box will appear as shown below: Click on the scale button. Try changing the y-axis scale to range from 13 to 25.

How do you zoom out on a chart?

Click the Zoom In button beneath the chart, which is available by default from the selected chart. Select the chart menu and click Zoom In. Shift-drag over an area of the chart. That is, press and hold the Shift key, and then drag the mouse pointer over the area of the chart into which you want to zoom.


2 Answers

Here is How I got the zoom with the dragToZoom explorer function

explorer: { 
        actions: ['dragToZoom', 'rightClickToReset'],
        axis: 'horizontal',
        keepInBounds: true,
        maxZoomIn: 4.0
}

the fiddle is here https://jsfiddle.net/4w626v2s/2/

also by just allowing it to zoom by scrolling

explorer: {
        axis: 'horizontal',
        keepInBounds: true,
        maxZoomIn: 4.0
}

the fiddle for scroll to zoom is here https://jsfiddle.net/5h7jxqq8/2/

like image 54
Leonard Kakande Avatar answered Sep 19 '22 10:09

Leonard Kakande


This seems to be working now with LineChart AND ColumnChart (even though this one is not documented).

var options = {
    explorer: {
        maxZoomOut:2,
        keepInBounds: true
    }
};

http://jsfiddle.net/duJA8/

like image 40
Sébastien Avatar answered Sep 20 '22 10:09

Sébastien