I have a google chart i want to show only seven days data to users on the graph, And they should be able to see the previous seven day data.
For example if i have data of 1/7/2017 to 15/7/2017
Intialy grpah should show only 8/7/2017 to 15/7/2017. But if users want they can go back to previous 1/7/2017 to 8/7/2017 results.
Now i am showing all 14 days data which doesn't seem good
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>
Google Visualization API Sample
</title>
</script> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
// Load google charts
google.charts.load('current', {'packages':['corechart','line']});
google.charts.setOnLoadCallback(seven_day_compare);
// Draw the chart and set the chart values
function seven_day_compare() {
var data = google.visualization.arrayToDataTable(
[["Date","likes","share"],["2017-07-01",30,20],["2017-07-02",20,20],["2017-07-03",16,10],["2017-07-4",10,15],["2017-07-5",31,66],["2017-07-6",20,15],["2017-07-7",2,5],["2017-07-8",8,6],["2017-07-09",30,20],["2017-07-10",20,20],["2017-07-11",16,10],["2017-07-12",10,15],["2017-07-13",31,66],["2017-07-14",20,15],["2017-07-15",2,5],["2017-07-16",8,6]]
);
// Optional; add a title and set the width and height of the chart
var options = {'title':'Compare like and share', 'width':550, 'height':400,'pointSize': 10,'hAxis':{
'slantedText': true,
'slantedTextAngle':30},'vAxis':{}};
// Display the chart inside the <div> element with id="differnt"
var chart = new google.visualization.LineChart(document.getElementById('chart'));
chart.draw(data, options);
}
</script>
</head>
<body style="font-family: Arial;border: 0 none;">
<div id = "chart"></div>
</body>
</html>
So basically i want to break the graph into seven days time periods Is it possible with google charts. Or any other suggestions
this is possible using a DataView
first, need to convert the first column to an actual date,
this can be done with a calculated column...
then use the
getFilteredRows
method to limit the date range shown on the chart...see following working snippet...
EDIT
use option -->
hAxis.ticks
-- to ensure which dates appear on the x-axisto build
ticks
dynamically, use data table / view method -->getColumnRange
,which returns an object with properties for
min
&max
see following working snippet...