3

I drew a bar diagram for my benchmarks in Graph-ET on Pharo. Does anybody know how to add the labels to x-axis? I want to write the name of the benchmark under the each of bars.

Janko Mivšek
  • 3,954
  • 3
  • 23
  • 29
Natalia
  • 33
  • 2

2 Answers2

3

Open a workspace, and type the following:

| chart |

chart := GETDiagramBuilder new.
chart verticalBarDiagram 
    models: ($a to: $z); 
    y: #asInteger;
    regularAxis;
    height: 200.

chart open.

"We use the same model elements"
($a to: $z) do: [ :value | 
    | bar label |
    "We define a label, and add it to the view"
    label := ROLabel elementOn: value asString.
    chart rawView add: label.

    "We get the bar, the gray element that grows up"
    bar := chart rawView elementFromModel: value.

    "Move the label below its corresponding bar"
    ROConstraint move: label below: bar ].

"Inserting high level labels"
chart rawView add: ((ROLabel red elementOn: 'Chart about my life') translateBy: 200 @ 0).
chart rawView add: ((ROLabel elementOn: 'Happiness') translateBy: -30 @ -40).
chart rawView add: ((ROLabel elementOn: 'Passing days') translateBy: 650 @ 210)

This is what you get with the code above

  • 1
    Thanks. By the way I added to your code a line to write the vertical labels. `'someString' joinUsing: Character cr.` – Natalia Sep 17 '13 at 21:24
1

In GraphET2 (which uses Roassal2) building charts like the one you wanted is way easier!

| chart |

chart := GET2Bar data: ($a to: $z).
chart
    y: #asInteger;
    title: 'Chart about my life';
    titleColor: Color red.
chart yAxis title: 'Happiness'.
chart xAxis addModelLabels:[:v | |s| s:= v asString. s,s,s,s.  ];
        verticalLabelsInverted; 
        title: 'Passing days'.
chart open.

Check it out here!

I hope it helps :)

Community
  • 1
  • 1