我有這種方法,其顯示使用GraphET的圖表:GraphET菲羅Smalltalk的標籤
displayChart: aPGResult
"Takes result of SQL query and calculates duration from activityend MINUS activitystart and draws bars of duration length (in days)"
| diagram values names |
values := OrderedCollection new.
names := OrderedCollection new.
aPGResult rows do: [:row | | data duration actStart actEnd a b monthA monthB job |
data := row rawData.
a := data at: 2.
b := data at: 3.
job := data at: 1.
monthA := (a copyFrom: 6 to: 7) asInteger.
monthB := (b copyFrom: 6 to: 7) asInteger.
actStart := Date newDay: ((a copyFrom: 9 to: 10) asInteger) month: (months at: monthA) year: ((a copyFrom: 1 to: 4) asInteger).
actEnd := Date newDay: ((b copyFrom: 9 to: 10) asInteger) month: (months at: monthB) year: ((b copyFrom: 1 to: 4) asInteger).
duration:= actEnd subtractDate: actStart.
duration = 0 ifTrue: [ duration := 1 ].
values add: duration.
names add: job ].
diagram := GETDiagramBuilder new.
diagram horizontalBarDiagram
models: values;
barWidth: 15;
width: 500;
color: Color blue;
regularAxisAsInteger;
xAxisLabel: 'Days';
yAxisLabel: 'Activity';
spacing: 2;
titleLabel: 'My Chart'.
diagram interaction popUpText.
^diagram open.
該方法採用從SQL查詢aPGResult結果並顯示水平條。 這一切工作正常,但我想標籤使用每個欄左邊的OrderedCollection名稱。我嘗試使用下面的代碼在此論壇上看到:
values do: [ :value |
| bar label |
label := ROLabel elementOn: value asString.
diagram rawView add: label.
bar := diagram rawView elementFromModel: value.
ROConstraint move: label onTheLeftOf: bar ].
但它給出錯誤:接收方的位置是零。這意味着elementFromModel方法找不到模型。
這看起來不錯。我怎樣才能把它變成一個魅力窗口? –
您能否將此答案標記爲正確,併爲此創建另一個問題。通過這種方式,搜索引擎可以更容易地找到「將GraphET2可視化變爲魅力窗口」。 –