1 Reply Latest reply on Apr 15, 2011 5:53 AM by Fletchgqc

    Trigger a function after LinearAxis.maximum is calculated?

    Fletchgqc Level 1

      I have two charts side-by-side and I want the Y-Scale of each to be the same. This simply means setting the LinearAxis.maximum property to the same value in both charts.

       

      At compile time I don't know what values will be in the charts, so I can't hard-code the maximum. Instead I need both charts to calculate their maximum values automatically (the default behaviour) and then I will simply find which of the maximums is greater and set that to be the maximum on the other chart as well.

       

      The problem: I can't figure out how to call a function directly after the maximum is calculated on a chart.

       

      My non-working (psuedo) code:

       

      function receiveValuesForChart1(event:ResultEvent) {

        chart1Values = event.result as ArrayCollection;

        applyNewMaximumIfNecessary();

      }

       

      // another similar function for chart2

       

      The problem with this code is that the function applyNewMaximumIfNecessary() is called BEFORE Flash calculates the automatic maximum! Must be something to do with the binding of the chart datasource to chart1Values. I need this function to be called after Flash calculates the automatic maximum.

       

      So currently I'm using an AWFUL HACK:

       

      function receiveValuesForChart1(event:ResultEvent) {

        chart1Values = event.result as ArrayCollection;

        var t:Timer = new Timer(100, 1);

        t.addEventListener('timer', applyNewMaximumIfNecessary);

        t.start();

      }

       

      This actually works here in my dev environment, but you're probably feeling ill just from reading that code. Sorry. So is there a way I can hook into some event or otherwise when LinearAxis.maximum is calculated in order to call my applyNewMaximumIfNecessary() function?

       

      Thanks for any help...

      Fletch.