Question

I use RaphaeJs to display colors extracted from an image in a pie chart. I am looking for a way to display an alert (for exemple) when clicking on one of the covers that make up the chart.

I tried the code below but without success.

var clickSomeSlice = function() {
    console.log(this.attrs.fill);
};
for (var index_i = 0; index_i < myChartPie.covers.length; index_i++) {
    myChartPie.covers[index_i].click(clickSomeSlice);
}

Solved:

Rapahel JS generates covers with #000 fill color and it places it above each color, I found colors stored in series attribute which is constituted with colors and covers

for (var index_i = 0; index_i < myChartPie.covers.length; index_i++) {
    myChartPie.covers[index_i].click(function(){
        console.log(myChartPie.series[this.id-data.length].attrs.fill);
    });
}
Était-ce utile?

La solution

edit

for (var index_i = 0; index_i < myChartPie.covers.length; index_i++) {
    myChartPie.covers[index_i].click(function(){            
         // look in the console in javascript debugger to see if the object has a color 
         console.log(this);
    });
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top