Closed nseb closed 5 years ago
uhm... it sounds an enhancement for CHART.JS. Otherwise you should set height pixel, depending on width at runtime by a plugin...
@nseb just being sure, you set a specific Fontsize on the ticks, doesn't it?
Yes , 8px
@nseb sorry for delay of reply. Reading again the issue, if I've understood well you would like to have ratioFactor between the width and height of the canvas, where height must calculated by ratioFactor. Correct?
@stockiNail , Yes ! For example , I have another problem with long label , in this case I must increase height ?
@nseb to set the ratio, we should act before drawing the chart. At the moment I haven't add the teh ratioFactor
as propety of chart options but you can set it by a plugin (in the meanwhile).
the following is the code:
chart.getOptions().setMaintainAspectRatio(false);
Set to false
the maintainAspectRatio
chart.getPlugins().add(new AbstractPlugin() {
@Override
public String getId() {
return "size";
}
@Override
public void onBeforeInit(AbstractChart<?, ?> chart, JavaScriptObject options) {
int w = chart.getCanvas().getParentElement().getOffsetWidth(); //get width of parent
chart.getCanvas().setWidth(w); // set width of parent
chart.getCanvas().setHeight(w/3); // apply ratio
}
});
This is simplest way. Of course we can:
ratioFactor
as property of chart optionsmaintainAspectRatio
equals to false
and ratioFactor
greater than 0 to all chartsAbove logic will be applied before drawing the chart, inside the AbstractChart class. What do you think?
@nseb About the above picture that you uploaded, 2 thoughts, from my side, if I may:
@stockiNail , thanks for your reply For Ratio, I will try the option with the plugin
@nseb Under the review we are doingfor jsinterop, I see that CHART.JS added new property aspectRatio
:
Name | Type | Default | Description |
---|---|---|---|
aspectRatio |
Number |
2 |
Canvas aspect ratio (i.e. width / height , a value of 1 representing a square canvas). Note that this option is ignored if the height is explicitly defined either as attribute or via the style. |
This is new and it's missing in Charba. We will implement soon.
@nseb added new property.
Here is part of the code:
chart.getOptions().setResponsive(true);
chart.getOptions().setMaintainAspectRatio(true);
chart.getOptions().setAspectRatio(3);
Here is the picture (w: 1539, h:513):
The aspect ratio is also maintained during the resize. We are preparing the new version 1.7.
Charba 1.7 released
I use maintainRatio to have a fairly consistent HMI, in some cases this is not enough, and setter the heigth pixel a little annoying depending on the size of the viewport. It's would be possible to have in addition to the property maintainRatio, a ratioFactor to determine the height according to the width, today by default, it's 1/2