简体   繁体   English

当我尝试在 Angular 6 中使用 billboard.js 图表库时遇到图表大小问题

[英]Facing issue in chart size while I am trying to use billboard.js chart library with Angular 6

I am trying to use billboard.js chart library with Angular 6 and facing issue in chart size.我正在尝试将 billboard.js 图表库与 Angular 6 结合使用,但面临图表大小的问题。 When the page load for first time, chart size is bigger than it's div container and when i change browser window size, chart's size is automatically adjusted according to div container.当页面第一次加载时,图表大小大于它的 div 容器,当我改变浏览器窗口大小时,图表的大小会根据 div 容器自动调整。

See the screenshot before and after window resize.查看窗口调整大小前后的屏幕截图。

Before在此处输入图片说明

After在此处输入图片说明

I have tried to lazy load graph as mentioned here , but it's not working.我曾尝试像这里提到的那样延迟加载图,但它不起作用。

Any help would be appreciated.任何帮助,将不胜感激。

Import AfterViewInit and add this method to the class.导入AfterViewInit并将此方法添加到类中。 This line of code resizes the chart after the chart is rendered.这行代码在图表呈现后调整图表的大小。

ngAfterViewInit() {
  this.charts[0].resize();    
}

You can also specify height and width to the resize function to resize chart to a specific size.您还可以为调整大小函数指定高度和宽度以将图表调整为特定大小。

resize({height: '200px', width: '400px'});

Check the documentation here - https://naver.github.io/billboard.js/release/latest/doc/Chart.html#resize检查此处的文档 - https://naver.github.io/billboard.js/release/latest/doc/Chart.html#resize

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我试图在我的角度组件中使用 Chart.js,但它没有显示图表图像,但是当我在 app.component.html 中使用它时,它可以工作 - I am trying to use Chart.js in my angular component, but it is not showing the chart image, but when I use it at app.component.html, it works 顶点图表填充 colors 面临 Angular 中的问题 - Apex chart fill colors facing issue in Angular 我正在将 Angular 版本从 4 更新到 7,我正面临这个问题 - I am updating angular version from 4 to 7 and i am facing this issue Angular 需要 Zone.js polyfill。 使用系统 js 我正面临这个问题 - Angular requires Zone.js polyfill. with system js i am facing this issue 我在我的角度组件中执行npm start时遇到编译问题 - I am facing a compilation issue while doing npm start in my angular component 在 angular 8 中的饼图上从 onClick 事件打开对话框时面临困难(使用 chart.js) - Facing difficulty in opening a dialog from onClick event on a pie chart in angular 8 (using chart.js) 我正在尝试使用 angular 中的 chart.js 创建一个简单的条形图,但出现错误,因为选项不存在“图例”类型 - I'm trying to use chart.js in angular to create a simple bar chart but I'm getting an error as 'legend' type doesn't exist for options 如何在 angular 7 中使用 chart.js - how to use chart.js in angular 7 如何在Angular2中使用chart.js? - How to use chart.js in Angular2? Angular4图表库 - Angular4 Chart Library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM