ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  calculate new data if viewer.isViewPortChangeEvent()
Posted by slaniwani on Feb-25-2011 00:55
Hi,

another question, but this time I didnt know the answer. :)
This script is affected : pythondemo_cgi\\zoomscrolldemo.py


Right now I have a dropdown list which includes 1 day, 7 day and 30day.
my Select Query :
"SELECT .... between now() and viewer.getCustomAttr(selectperiod)..."
and this is included in the def drawChart():


How can I calculate the select query with the given data length, I select when I zoom in?

It has to do something with that, correct?
    if viewer.isViewPortChangedEvent() :
        # Is a view port change event from the Javascript ChartViewer, so we should get the selected
        # date range from the ChartViewer view port settings.
        duration = endDate - startDate
        viewPortStartDate = startDate + int(0.5 + viewer.getViewPortLeft() * duration)
        viewPortEndDate = viewPortStartDate + int(0.5 + viewer.getViewPortWidth() * duration)


For Example:

I select a date range of 7 Day(from my drop down list) and click on UpdateChart.

Now, if I zoom into this data, I want that the  function def drawChart is called again but the Trend Line and the slope, intercept and so on, should be recalculated with the date range I select with the zoom In function.

My trendlayers gets the data from the mysql query and will be displayed.

I really dont know how to do this

  Re: calculate new data if viewer.isViewPortChangeEvent()
Posted by Peter Kwan on Feb-25-2011 02:06
Hi slaniwani,

In the original sample code, we have something like:

if viewer.isViewPortChangedEvent() :

    .....

else :

    .....
    viewPortStartDate = chartTime(startYear, startMonth, 1) + (startDay - 1) * 86400
    viewPortEndDate = chartTime(endYear, endMonth, 1) + (endDay - 1) * 86400

I think you just need to change the code inside the "else" block to

    viewPortEndDate = endDate
    viewPortStartDate = viewPortEndDate - 86400 * int(viewer.getCustomAttr("selectperiod"))

The above assumes you have a dropdown list called "selectperiod", and it contains integers representing days, and that you have passed this HTML control to the server during AJAX request (eg. by including this control in the controlsToSync list).

Hope this can help.

Regards
Peter Kwan