简体   繁体   English

Ionic V6 和 highchart-angular 无法正确显示

[英]Ionic V6 and highchart-angular doesnt display correctly

I'm implementing the highcharts in a ionic 6 app using the highchart-angular library and when i load the component the chart doesnt adapt to the size of the page我正在使用 highchart-angular 库在 ionic 6 应用程序中实现 highcharts,当我加载组件时,图表不适应页面大小

I'm using the blank ionic template and using a default sample of the highchart-angular我正在使用空白离子模板并使用 highchart-angular 的默认示例

Here is my code https://stackblitz.com/edit/angular-ivy-asdse6?file=src%2Fapp%2Fhome%2Fhome.page.scss这是我的代码https://stackblitz.com/edit/angular-ivy-asdse6?file=src%2Fapp%2Fhome%2Fhome.page.scss

my html is this我的 html 是这个

<ion-header [translucent]="true">
  <ion-toolbar>
    <ion-title> Blank </ion-title>
  </ion-toolbar>
</ion-header>

<ion-content [fullscreen]="true">
  <ion-header collapse="condense">
    <ion-toolbar>
      <ion-title size="large">Blank</ion-title>
    </ion-toolbar>
  </ion-header>

  <div id="container">
    <highcharts-chart
      [Highcharts]="highcharts"
      [options]="chartOptions"
      class="chart"
      (chartInstance)="setChart($event)"
      (resized)="chart?.reflow()"
    >
    </highcharts-chart>
  </div>
</ion-content>

and the component typescript is this和组件 typescript 是这个

import {
  AfterViewInit,
  Component,
  ElementRef,
  OnInit,
  ViewChild,
} from '@angular/core';
import * as Highcharts from 'highcharts';

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage implements OnInit, AfterViewInit {
  @ViewChild('chart', { static: false })
  container: ElementRef<HTMLDivElement>;
  chart: Highcharts.Chart;
  stack: Highcharts.OptionsStackingValue = undefined;
  chartType = 'bar';
  highcharts: typeof Highcharts = Highcharts;
  chartOptions: Highcharts.Options = {
    chart: {
      type: this.chartType,
    },
    title: {
      text: '',
    },
    legend: {
      enabled: false,
    },
    plotOptions: {
      series: {
        stacking: this.stack,
      },
    },
    series: [
      {
        data: [10, 3],
        type: undefined,
      },
      {
        data: [100, 3],
        type: undefined,
      },
    ],
  };

  constructor() {}

  ngAfterViewInit(): void {}

  setChart(chart: Highcharts.Chart) {
    this.chart = chart;
  }

  ngOnInit() {}
}

i found the issue with the code我发现了代码的问题

to make the chart to fit the container i have to add and event and call the.reflow();为了使图表适合容器,我必须添加事件并调用 the.reflow(); method like this像这样的方法

  chartCallback(chart): void {
    setTimeout(() => {
      chart.reflow();
    }, 0);
  }

and in the component like this在这样的组件中

  <highcharts-chart
    class="chart"
    [Highcharts]="highcharts"
    [options]="chartOptions"
    (chartInstance)="setChart($event)"
    [callbackFunction]="chartCallback"
    (resized)="chart?.reflow()"
  >
  </highcharts-chart>

I also updated the stackblitz code我还更新了 stackblitz 代码

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

相关问题 Ionic v5 到 v6 更新失败? - Ionic v5 to v6 update failed? 在更新到最新的Angular(v6到v7)之后,BehaviorSubject(在Ionic Project中)表现得很奇怪 - BehaviorSubject (in Ionic Project) behaves strangely after update to latest Angular (v6 to v7) IONIC/Angular:HTML 不显示 ts 文件中的信息 - IONIC/Angular: HTML doesnt display information from ts file 如何将 SYSTEM_ALERT_WINDOW 与 ionic v6 Cordova 一起使用 - How use SYSTEM_ALERT_WINDOW with ionic v6 Cordova 多文档选择器或输入 type="file" Ionic v6 cordova - Multiple document picker or input type="file" Ionic v6 cordova 构建 Ionic v6 cordova android angular13 应用程序返回错误“发生未处理的异常:项目目标不存在。” - Building Ionic v6 cordova android angular13 app returns ERROR "An unhandled exception occurred: Project target does not exist." 无法找到 ionic v4 的 ng 命令,但在使用 ionic v6 时可以 - Unable to find ng command for ionic v4 but otherwise ok when using ionic v6 如何影响 Ionic v6 电容器中的自定义谷歌地图样式? - How to affect a custom google map style in Ionic v6 capacitor? Ionic v6 Ion-accordion 默认打开第一项 - Ionic v6 Ion-accordion open first item by default Ionic v6 透明体 (@capacitor/google-maps) - Ionic v6 transparent body (@capacitor/google-maps)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM