【问题标题】:Graph-ET x-axis labelsGraph-ET x 轴标签
【发布时间】:2013-09-16 15:11:43
【问题描述】:

我在 Pharo 上的 Graph-ET 中为我的基准测试绘制了条形图。有没有人 知道如何将标签添加到 x 轴?我想在每个条形下方写下基准的名称。

【问题讨论】:

    标签: smalltalk pharo roassal


    【解决方案1】:

    打开一个工作区,然后输入以下内容:

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

    【讨论】:

    • 谢谢。顺便说一句,我在您的代码中添加了一行来编写垂直标签。 'someString' joinUsing: Character cr.
    【解决方案2】:

    在 GraphET2(使用 Roassal2)中,构建您想要的图表要容易得多!

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

    看看here

    希望对你有帮助:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多