Is there a way to reduce the vertical white space between the elements of a chart in Vaadin Charts 2?
See the orange boxes in this screen shot.
While I understand this makes for an attractively laid-out chart, in my case I am assembling many charts with many lines within a layout. So I would like to maximize the amount of pixel used for the chart’s plot area.
The first orange box is not actually white space within the chart. Or, if it is, I do not know how to change it.
The second orange box is "margin" on the Title element. You can call the setMargin
method on the Title
object. For a small chart like that shown, I have found a value of 5
to be useful.
this.getConfiguration().getTitle().setMargin( 5 );
Likewise, the Legend
object also offers a setMargin
command. Again, I have found a value of 5
to be useful.
this.getConfiguration().getLegend).setMargin( 5 );
The overall chart remains the same size. Only the space within that overall chart is changed, reallocated.
With both of these setMargin
methods, the white space between the object and the plot area is reduced. The freed pixels are allocated to the plot area.
The difference can be significant, especially in smaller charts. Here is a screenshot of before and after adding calls to set margin to 5
. The scaling of the Y-axis changed because of the newly-gained pixels.