Sign in to follow this  
paulguz

Getting chart slice index

Recommended Posts

(Apologies for the repost; I think I originally had this in the wrong subforum)


 


Hi,


 


In my collaboration tool, I need to capture the slice event and programatically slice the same chart on a different browser.


 


The function slicePlotItem() requires an index for the data item to be sliced, but the data argument of slicingStart (or slicingEnd) does not contain this index.


 


How do you suggest determining the index of the sliced data?


 


Thanks,


 


Paul


Edited by paulguz

Share this post


Link to post
Share on other sites

A simple solution (albeit one which shouldn't be necessary) is to compare the chart's slices at the start and end of the slice, and find the slice that changed, like so:

 var chartSliceStateStart = []; //the state of the chart's slices before slicing
        var chartSliceStateEnd = []; //the state of the chart's slices after slicing


        FusionCharts.addEventListener('slicingStart', function (event, args) {

            chartSliceStateStart = [];

            for (var i=0; i < event.sender.getJSONData().data.length; i++)
            {
                chartSliceStateStart.push(event.sender.isPlotItemSliced(i));
            }

        });

        FusionCharts.addEventListener('slicingEnd', function (event, args) {
            callServerHub(function () {

                var sliceIndex = 0;
                var clickedSliceFound = false;

                chartSliceStateEnd = [];

                for (var i = 0; i < event.sender.getJSONData().data.length; i++) {
                    chartSliceStateEnd.push(event.sender.isPlotItemSliced(i));
                }

                var i =0;
                while (!clickedSliceFound && i < chartSliceStateStart.length)
                {
                    clickedSliceFound = chartSliceStateStart[i] != chartSliceStateEnd[i];
                    sliceIndex = i;
                    i++;
                }

                if (clickedSliceFound) {
                    // do something with sliceIndex
                }
            });
        });

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this