Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top