DmitryBaranovskiy / g.raphael

Charts for Raphaël
http://g.raphaeljs.com/
1.52k stars 435 forks source link

barchart label not working in milestone 0.5 #129

Open germanftorres opened 12 years ago

germanftorres commented 12 years ago

Hi!

I'm trying to label a single series barchart and it simply doesn't work. I have modified the test/barchart.html example trying to label the first chart. It gives an exception an the other three charts don't get rendered. It appears as the labelise method gets called on an object which doesn't support it. I have tried to fix de issue but I'm not really good at javascript.

Thanks

Germán

        window.onload = function () {
            var r = Raphael("holder"),
                data1 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
                data2 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
                data3 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
                txtattr = { font: "12px 'Fontin Sans', Fontin-Sans, sans-serif" };

            r.text(160, 10, "Single Series Chart").attr(txtattr);
            r.text(480, 10, "Multiline Series Chart").attr(txtattr);
            r.text(160, 250, "Multiple Series Stacked Chart").attr(txtattr);
            r.text(480, 250, 'Multiline Series Stacked Vertical Chart. Type "round"').attr(txtattr);

            var chart = r.barchart(10, 10, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10]], 0, {type: "sharp"});

            //
            // here we get the error 'object does not support labelise property or method'
            //
            chart.label(["Uno", "Dos", "Tres", "Cuatro", "Cinco", "Seis", "Siete", "Ocho"]);

            r.barchart(330, 10, 300, 220, data1);
            r.barchart(10, 250, 300, 220, data2, {stacked: true});
            r.barchart(330, 250, 300, 220, data3, {stacked: true, type: "round"});
        };
rzurad commented 12 years ago

Ah, looks like when we moved from a namespace to a prototype, we mucked up a few references. Looks like there's a few logical errors in how bar charts are trying to apply labels. I'll look into it.

karolk commented 12 years ago

Just to let you know my current stance on the labels - from what I noticed textual labels claim all space there is for the chart, so if they are really long they will squish the graph. I am planning to prepare specific test cases and deal with this when I am finished with docs. I am also tempted to experiment with dividing the code into axis, legend and actual graph, because they are intertwined at the moment. Axis already lives on the prototype and legend code could be moved there.

rzurad commented 12 years ago

I agree. There is lots and lots of room to refactor the codebase into something much more modular, that way there is less coupled code that all the different graph types can leverage.

amuraco commented 12 years ago

Has there been any progress on fixing these issues? Currently the labels on a barchart just throw an error.

nullvariable commented 12 years ago

I'm still getting

Object #<a> has no method 'labelise' 

when trying to add labels, is this going to be fixed or are we on our own with this?

pierrenel commented 12 years ago

Yep, still having this issue.

torgeir commented 12 years ago

+1

theirishpenguin commented 12 years ago

+1

saimn commented 12 years ago

I have fixed barchart labels for my own purpose, the commit is there: saimn/c2c-stats@aa4b43224400c9162ca30a443b32284a4d604f90

I'm not a javascript expert and I didn't test all barchart options but it works for me : it works with stacked (my commit msg is wrong) and non-stacked, hbarchart and vbarchart. However there is another bug with tooltips and raphael 2.1.0. With raphael 2.0.2 it's working fine.

theirishpenguin commented 12 years ago

Thanks @saimn You're fix kind of worked in my case. When I applied it, the actual column values appeared on top of the bars (rather than a distinct legend that I could specific underneath them). What I'd like is a barchart like outlined here http://masonoise.wordpress.com/2009/12/29/bar-and-pie-charts-with-raphaeljs though I think the blog poster uses on older version of raphael and graphael (0.4).

I'm using the interactive barchart and like you said, I had to use raphael 2.0.2 to see any effect.

saimn commented 12 years ago

@theirishpenguin for barchart, labels are shown by default at the top of the bars. You can use .label( [...], true) to put labels at the bottom. For vbarchart there is a corresponding option to show lables on the right instead of left which is the default.

theirishpenguin commented 12 years ago

@saimn Thanks for clarifying that! It now works as expected, with one small change - I had to wrap the labels inside an extra pair of square brackets, for example

r.barchart(
  10, 10, 300, 220,
  [[55, 20, 13, 32, 5, 1, 2, 10, 11,44, 64, 23]],
  {type: "round"}
).hover(fin, fout).label([['J','F','M','A','M','J','J','A', 'S', 'O', 'N','D']], true);

Thanks again. Was banging my head against a wall until you provided your solution!

abhisec commented 12 years ago

Is this being maintained? The bar chart labels not working is kind of critical? Are the authors maintaining this?

baileyspace commented 12 years ago

+1

hansoksendahl commented 12 years ago

+1

ghost commented 12 years ago

Thanks @saimn, I've gotten the correct labels to show but they are straight after another rather than below their individual bars, and I still get an error

TypeError: 'undefined' is not an object (evaluating 'bars[j][i].x')

Help would be appreciated :)

mattleff commented 11 years ago

+1

wittxiao commented 11 years ago

Anybody know the solution? I got the same problem with 0.51

mcasperson commented 11 years ago

+1

tian-yi commented 11 years ago

+1

tian-yi commented 11 years ago

For people who's still looking for solutions, try using https://github.com/jhurt/g.raphael/blob/master/g.bar.js which fixes this issue and worked pretty well for me

mikeshultz commented 11 years ago

+1

trollfred commented 10 years ago

+1 and solution from tianyi33 works

dlaxar commented 10 years ago

+1 this is still unresolved...

flyon commented 10 years ago

+1 yes still unresolved ... defenitly need labels, and I'm getting the same error "Uncaught TypeError: Object # has no method 'labelise' "

        var chart = r.barchart(10, 10, 550, 300, [
            [5.5, 2.0, 7.6, 9.5]
        ]).hover(fin, fout).label([['a','b','c','d']]);
jayarjo commented 10 years ago

+1

villian commented 9 years ago

still problem with label s