g.raphael bar chart with clickable bars

2.5k views Asked by At

I'd like to make each segment of a stacked bar graph (horizontal in my case) clickable to a specific hyperlink (basically "drill down"). I don't think this functionality is in g.bar.js, but has anyone done this or can point me in the right direction? Would also be useful on dot charts.

2

There are 2 answers

0
jjnevis On BEST ANSWER

Okay, posting the question seems to have motivated me to figure it out...

Using the demo bar chart provided, I added a line to the fin function:

  fin = function () {
    this.flag = r.g.popup(this.bar.x, this.bar.y, this.bar.value || "0").insertBefore(this);
    /* add this for linked bars */
    this.attr({href: "http://myurl.com/"+this.bar.x+"/"+this.bar.y+"/"+this.bar.value});
  },
0
Flion On

the suggested this.attr above didn't work for me, but this did:

fin = function () {
    this.flag = r.g.popup(this.bar.x, this.bar.y, this.bar.value || "0").insertBefore(this);

    /* add click event to bar */
    this.click(function(){
        location.href = "http://myurl.com";
    });
},