Hi ,
I made some changes in my code. Now instead of calling web service directly
i am using $ajax to fetch data.
How to get the same result as above with this code.
adding chart.set visible range after calling getData() does not work. Do i
need to draw the chart first and then set the chart range and redraw it?
google.visualization.events.addListener(chart, 'ready', function () {
document.getElementById('DropDownList1').onchange = function ()
{
var dropDown = document.getElementById('DropDownList1');
var value = dropDown[dropDown.selectedIndex].value;
GetData(value);
var range = data.getColumnRange(0);
chart.setVisibleChartRange(new Date(range.max.getFullYear()
- 1, range.max.getMonth(), range.max.getDate()), null); //null sets the
maximum date
chart.draw(data, options);
}
});
function GetData(custId)
{
var jsondata = "";
$.ajax({
type: "POST",
url: 'AnnotationCharts.aspx/GetData',
contentType: "application/json; charset=utf-8",
dataType: "json",
data: '{"custId":' + '"' + custId + '"' + '}',
async: false,
success: function (msg) {
jsondata = msg.d;
}
});
// Create our data table out of JSON data loaded from server.
data = new google.visualization.DataTable(jsondata);
}
On Tuesday, September 16, 2014 4:54:52 AM UTC+5:30, Andrew Gallant wrote:
>
> I believe you want to set the chart range after redrawing. Try using a
> "ready" event handler to do this:
>
> function Callback(result) {
> data = new google.visualization.DataTable(result);
> var range = data.getColumnRange(0);
> google.visualization.events.addOneTimeListener(chart, 'ready',
> function () {
> chart.setVisibleChartRange(new Date(range.max.getFullYear() - 1,
> range.max.getMonth(), range.max.getDate()), null); //null sets the maximum
> date
> }
> chart.draw(data,options);
> }
>
> On Monday, September 15, 2014 3:27:48 AM UTC-4, Shivani Kanakhara wrote:
>>
>> Hi,
>> I am using annotation chart where the data changes according to item
>> selected from DropDownlist.
>> It works fine . But every time the data is loaded i want 1 year range to
>> be selected by default.
>> I used chart.setVisibleRange() but its not working..don't know why.
>> I have used webService to load data.
>> Here's my code:
>>
>> google.visualization.events.addListener(chart, 'ready', function () {
>> document.getElementById('DropDownList1').onchange = function
>> () {
>>
>> var dropDown = document.getElementById('DropDownList1');
>> var value = dropDown[dropDown.selectedIndex].value;
>> ChartsDemo.WebService1.GetData(value, Callback);
>>
>> }
>>
>> function Callback(result) {
>>
>> data = new google.visualization.DataTable(result);
>> var range = data.getColumnRange(0);
>> chart.setVisibleChartRange(new
>> Date(range.max.getFullYear() - 1, range.max.getMonth(),
>> range.max.getDate()), null); //null sets the maximum date
>> chart.draw(data,options);
>> }
>>
>>
>> });
>>
>
--
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.