gtoolkit icon indicating copy to clipboard operation
gtoolkit copied to clipboard

Plotter line chart assumes dates on X axis by default

Open hellerve opened this issue 1 year ago • 0 comments

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

hellerve avatar Aug 06 '24 10:08 hellerve