g.raphael icon indicating copy to clipboard operation
g.raphael copied to clipboard

barchart label not working in milestone 0.5

Open germanftorres opened this issue 14 years ago • 27 comments

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"});
        };

germanftorres avatar Nov 12 '11 10:11 germanftorres

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.

rzurad avatar Nov 15 '11 06:11 rzurad

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.

karolk avatar Nov 16 '11 19:11 karolk

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.

rzurad avatar Nov 16 '11 19:11 rzurad

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

amuraco avatar Feb 08 '12 14:02 amuraco

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?

nullvariable avatar Mar 07 '12 14:03 nullvariable

Yep, still having this issue.

pierrenel avatar Mar 20 '12 16:03 pierrenel

+1

torgeir avatar Mar 27 '12 13:03 torgeir

+1

theirishpenguin avatar Apr 02 '12 19:04 theirishpenguin

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.

saimn avatar Apr 03 '12 07:04 saimn

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.

theirishpenguin avatar Apr 03 '12 12:04 theirishpenguin

@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.

saimn avatar Apr 03 '12 13:04 saimn

@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!

theirishpenguin avatar Apr 04 '12 12:04 theirishpenguin

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

abhisec avatar Apr 25 '12 20:04 abhisec

+1

baileyspace avatar May 08 '12 16:05 baileyspace

+1

hansoksendahl avatar Jun 20 '12 19:06 hansoksendahl

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 :)

ghost avatar Jul 09 '12 15:07 ghost

+1

mattleff avatar Sep 27 '12 22:09 mattleff

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

wittxiao avatar Oct 16 '12 14:10 wittxiao

+1

mcasperson avatar Oct 20 '12 10:10 mcasperson

+1

tian-yi avatar Nov 28 '12 15:11 tian-yi

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

tian-yi avatar Nov 29 '12 09:11 tian-yi

+1

mikeshultz avatar Mar 19 '13 20:03 mikeshultz

+1 and solution from tianyi33 works

trollfred avatar Nov 11 '13 11:11 trollfred

+1 this is still unresolved...

dlaxar avatar Nov 26 '13 07:11 dlaxar

+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']]);

flyon avatar Dec 26 '13 14:12 flyon

+1

jayarjo avatar Apr 27 '14 17:04 jayarjo

still problem with label s

villian avatar Apr 06 '15 12:04 villian