I created a dashboard application using Angular9 and ng2 charts. The application has ability to drag and drop charts on a Gridster layout and create Dashboards which loads in the Home page.
ng2 charts are set responsive true through chart options, It works all fine except in small screens.
I have following issues in small screens
Gridster is set mobile responsive, so in small screens its removing grid layout and stacking the items. The charts are overlapping.
The legend and label is taking up all the space and chart is either very small or not visible at all.
I think the below steps will fix the issue.
Set the height of canvas for small screens. I cannot set the height in the canvas html as these charts are dragged and dropped and the dashboard widgets are created interactively. Is there a way to set the canvas height only in small screens?
Is there a way to hide the legend only on small screens
Is there a way to change the font size of Title to smaller one on small screens.
var pieChartOptions: ChartOptions = { responsive: true, plugins: { title: { display: true, font: { size: (ctx) => window.innerWidth > 700 ? 8 : 6 } }, legend: { position: 'right', display: (ctx) => window.innerWidth > 700, labels: { fontSize: 6, usePointStyle: true } } };
This chart options is sent as Input to the chart component which has html
<canvas baseChart width="2" height="1"
[datasets]="ChartData"
[labels]="ChartLabels"
[options]="ChartOptions"
[legend]="ChartLegend"
[chartType]="ChartType"
[plugins]="ChartPlugins">
Please advise.
Thanks in advance sresree