GWT: height of charts legend and title are inside graph? #61
-
Hi *! I am a bit confused about positioning legend and title! The whole chart has e.g. 300px (including legend, title, etc.) But i think there is maybe a problem drawing this on canvas? |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments
-
It is weird... Charba doesn't do anything to change layout which is automatically calculated by Chart.js. |
Beta Was this translation helpful? Give feedback.
-
@MartinSchwarzbauer I tested with my charts. Here is the code: BarChartWidget chart = new BarChartWidget();
chart.setHeight("300px");
chart.getOptions().setResponsive(true);
chart.getOptions().setMaintainAspectRatio(false); // <--- DISABLES maintain aspect ratio
chart.getOptions().getTitle().setDisplay(true); // <-- ENABLES title
chart.getOptions().getTitle().setText("My first chart");
BarDataset dataset = chart.newDataset();
dataset.setLabel("dataset 1");
dataset.setBackgroundColor(HtmlColor.CORNFLOWER_BLUE.alpha(0.2));
dataset.setBorderColor(HtmlColor.CORNFLOWER_BLUE);
dataset.setBorderWidth(1);
dataset.setData(20, 5, 40, 35, 50, 70, 80);
chart.getData().setLabels("January", "February", "March", "April", "May", "June", "July");
chart.getData().setDatasets(dataset);
CartesianCategoryAxis axis1 = new CartesianCategoryAxis(chart);
axis1.setDisplay(true);
axis1.getTitle().setDisplay(true);
axis1.getTitle().setText("Month");
CartesianLinearAxis axis2 = new CartesianLinearAxis(chart);
axis2.setDisplay(true);
axis2.getTitle().setDisplay(true);
axis2.getTitle().setText("Value");
axis2.getTicks().setDisplay(true);
chart.getOptions().getScales().setAxes(axis1, axis2);
RootPanel.get().add(chart); When you you set the dimension (mainly height) you should disable the Here the result of above sample: |
Beta Was this translation helpful? Give feedback.
-
Here is my source: ui-binder:
Source:
|
Beta Was this translation helpful? Give feedback.
-
@MartinSchwarzbauer I was able to reproduce the issue. This is with DisclosurePanel: Here with HTML Panel: It sounds better with Html panel but I see something weird anyway. |
Beta Was this translation helpful? Give feedback.
-
@MartinSchwarzbauer I have checked more in details you axis configuration and there is a property which is the root cause of the rendering. Remove the bounds setting in the linear axis or set to Bound.TICKS (instead of Bound.DATA), and it works. y_axis.setBounds(Bounds.TICKS); Anyway the Chart.js community is having a look because there is a weird behavior: |
Beta Was this translation helpful? Give feedback.
-
The issue has been solved by chartjs/Chart.js#9181. |
Beta Was this translation helpful? Give feedback.
-
Chart.js version 3.3.2 has been added to the master branch. With that, the issue about the usage of Bounds.DATA has been solved. |
Beta Was this translation helpful? Give feedback.
-
Sorry for my late replay! Thank you very much - everything is working as expected! |
Beta Was this translation helpful? Give feedback.
@MartinSchwarzbauer I have checked more in details you axis configuration and there is a property which is the root cause of the rendering.
Remove the bounds setting in the linear axis or set to Bound.TICKS (instead of Bound.DATA), and it works.
Anyway the Chart.js community is having a look because there is a weird behavior:
chartjs/Chart.js#9178