在Angular中渲染Apex图表时,如果出现图表无法完全渲染的问题,可能是因为图表容器的大小没有被正确设置。以下是示例代码,演示如何在正确设置图表容器大小后,成功渲染Apex图表:
HTML代码:
TypeScript代码:
import { Component, ViewChild, AfterViewInit } from '@angular/core'; import ApexCharts from 'apexcharts';
@Component({ selector: 'app-chart', template: '
' }) export class ChartComponent implements AfterViewInit { @ViewChild('chartContainer') chartContainer;ngAfterViewInit() { const options = { chart: { type: 'line', height: 350 // 设置图表容器高度 }, series: [{ data: [30, 40, 35, 50, 49, 60, 70, 91, 125] }], xaxis: { categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999] } };
const chart = new ApexCharts(this.chartContainer.nativeElement, options);
chart.render();
} }
在上面的代码中,我们设置了图表容器的高度,以确保图表可以完全渲染。您可以根据自己的需求进行更改。