gtoolkit
gtoolkit copied to clipboard
Plotter line chart assumes dates on X axis by default
The default formatter on GtPlotterLineChart only works with date values. This means that for a simple plot such as this:
thousandSquares := (1 to: 1000)
collect: [ :aNumber | aNumber -> (aNumber * aNumber) ].
data := GtPlotterDataGroup new values: thousandSquares.
chart := GtPlotterLineChart new
with: data;
valueX: #key;
scaleX: GtPlotterLinearScale new;
valueY: #value;
scaleY: GtPlotterLinearScale new.
chart
the formatter will error. This can be circumvented by a custom formatter like so:
thousandSquares := (1 to: 1000)
collect: [ :aNumber | aNumber -> (aNumber * aNumber) ].
data := GtPlotterDataGroup new values: thousandSquares.
chart := GtPlotterLineChart new
with: data;
valueX: #key;
scaleX: GtPlotterLinearScale new;
labelFormatX: [ :x | x asString ]; "this is the new line"
valueY: #value;
scaleY: GtPlotterLinearScale new.
chart
But it seems wrong to require all X axis values to be dates by default. Maybe the formatter can be generalized a bit.
Cheers