简体   繁体   中英

How to format chart in Roassal 3?

I made a chart following the examples in the documentation. I find the title and x/y labels too close to the plot itself, and the tick labels too small. How do I format them?

x := -3.14 to: 3.14 count: 100.
y := x sin.

c := RSChart new.
p := RSLinePlot new x: x y: y.
c addPlot: p.

c title: 'Sine function'.
c xlabel: 'X axis'.
c ylabel: 'Y axis'.

c addDecoration: RSHorizontalTick new.
c addDecoration: RSVerticalTick new.
c open

图表

The way the graph is constructed it uses the default offset of 5 for X axis and -5 for Y axis in the initialize of RSXLabelDecoration or RSYLabelDecoration respectively.

To move the titles around you have to create them yourself instead of using xlabel or ylabel .

You whould have to replace these two lines of code:

c xlabel: 'X axis'.
c ylabel: 'Y axis'.

with:

xAxisDecoration := c addDecoration: (RSXLabelDecoration new title: 'X axis'; offset: 15).
yAxisDecoration := c addDecoration: (RSYLabelDecoration new title: 'Y axis'; offset: -15).

The result:

XY轴移动

Edit - forgot about the tick labels

To adjust the font size you need to add a message fontSize when creating a RSHorizontal(Vertical)Tick

The affected code would look like this:

c addDecoration: (RSHorizontalTick new fontSize: 10).
c addDecoration: (RSVerticalTick new fontSize: 10).

Producing this result:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM