3 Replies Latest reply: Feb 24, 2014 1:11 AM by Tom Petrus RSS

    Apex 4.2 anychart flash, add

    carlos_tos

      If I want to add some interactivity to the chart that I created with Apex I need to add an event listener like this:

       

      // Create new chart

      var chart = new AnyChart();

      // Add event handler for point event

      chart.addEventListener('pointClick', onPointClick);

       

      But I am using the wizard chart created from the APEX GUI, so I did not create the anychart object in my code such as

       

       

      I would have to know the object name that was created for my chart by APEX.

      Then I could code :

      OBJECTNAMECREATEDBYAPEX.addEventListener('pointClick', onPointClick);

       

      Can anyone help?

       

      Thank you.

      Carlos

        • 1. Re: Apex 4.2 anychart flash, add
          Tom Petrus

          Give the chart region a static id, then you can use this to get the chart object:

          AnyChart.getChartById($("#chart1_chart object")

           

          Where "chart1" is the static id, and "chart1_chart" is an element being created in the region. Thus, just concatenate your static id with "_chart". "object" will select the anychart object element.

          • 2. Re: Apex 4.2 anychart flash, add
            carlos_tos

            Excellent I can go further now but hit another problem.

             

            I set the id of the chart region to p41chart, and I checked then page source an I saw that it had a id="p41chart_chart" so I am on the right track.

             

            I created a button which is running a Dynamic Action.

             

            In the dynamic action attached to this button a write this code

            -----------------------

            var chart=AnyChart.getChartById($("#p41chart_chart object"));

            chart.addEventListener('pointClick', onPointClick);

            chart.addEventListener('pointDoubleClick', onPointDoubleClick);

            --------------------------

            On Selection Type of Dynamic Action I set DOM Object  with value      p41chart_chart

             

            When I press the button I am getting

            TypeError: chart is null in chart.addEventListener('pointClick', onPointClick);

            I read that getChartById had to be called after the OnDraw of the chart but since I call this from a button the chart is fully rendered when I press the Button, however chart still comes back as null.

            Any ideas for me to try.

            Thank you
            Carlos

             

            • 3. Re: Apex 4.2 anychart flash, add
              Tom Petrus

              Ah sorry, I forgot something (Copy-paste blundering). The point of giving the region a static id is indeed to retrieve the object element, though not to get the anychart object with it. The getChartById expects the id of the object element, not that element itself. So:

              AnyChart.getChartById($("#chart1_chart object").attr("id"))

               

               

               

              And that'll correctly fetch you the AnyChart object!