highcharts 在单击或悬停在任何位置之前,Angular5不会呈现组件

xdyibdwo  于 2023-08-05  发布在  Highcharts
关注(0)|答案(3)|浏览(139)

我有这个问题,这是打破我的头现在,我不能弄清楚是什么问题。我有一个名为device-form的表单,它是使用路由从 Jmeter 板调用的。设备表单有4个选项卡(角材质),第二个选项卡必须显示Highchart组件,当您选择该选项卡时,会显示容器,但不会显示图表。如果你等待,图表将永远不会出现,但如果你点击任何地方的图表出现,也如果你悬停一些项目与鼠标,或如果你调整屏幕!!
x1c 0d1x的数据
App-chart-box.component.html:

<mat-card fxFlex="100%" fxLayout="row">
<mat-card-title></mat-card-title>
<mat-card-content>
    <mat-tab-group class="form-wizard tab-group">
        <mat-tab *ngFor="let chart of charts; let i = index">
            <ng-template mat-tab-label>
                {{ chart.sensorTypeName }}
            </ng-template>
            <div class="tab-content">
                <vr-chart class="card-img-top" [title]="chart.sensorTypeName" [yTitle]="chart.sensorTypeUnit" type="spline" [series]="chart.series"
                    [period]="period" [minThreshold]="minThreshold" [maxThreshold]="maxThreshold"></vr-chart>
            </div>
        </mat-tab>
    </mat-tab-group>
</mat-card-content>
<mat-card-actions>
    <small class="footer">Last updated: {{ dateUpdated }}</small>
</mat-card-actions>

字符串
device-form.component.html:

<mat-tab>
      <ng-template mat-tab-label>
        <div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px">
          <span>Statistics</span>
        </div>
      </ng-template>
      <div fxFlex="100%" class="shipping-address" fxLayout="column">
        <mat-form-field class="select-period">
          <mat-select placeholder="{{ 'DEVICE_FORM.PERIOD' | translate }}" [(ngModel)]="filterPeriodSelected" (change)="loadDeviceChart()">
            <mat-option *ngFor="let period of chartPeriods" [value]="period.value">
              {{ period.label | translate }}
            </mat-option>
          </mat-select>
        </mat-form-field>
        <!-- <div *ngIf="deviceCharts.length == 0" class="alert bg-primary alert-dismissible fade show" role="alert">
          <strong class="ng-tns-c6-44"> {{'MESSAGE.NO_DATA_TO_SHOW' | translate}}</strong>
        </div> -->
        <vr-chart-box *ngIf="deviceCharts" class="fix-width" [charts]="deviceCharts" [period]="filterPeriodSelected"></vr-chart-box>
      </div>
    </mat-tab>


正如你看到的app-chart-box组件呈现,实际上我们总是可以看到页脚加载,总是,但图表的主体不出现,直到点击或悬停o什么。



更新:实际上我有一个非常相同的问题与一个表,其中充满了来自API的数据,当你改变了一个下拉列表在那里的主 Jmeter 板页面,表组件总是监听.onCompanyChange.subscribe,读取所有的数据,但该表是不显示,直到你点击或悬停或任何事件.这是代码:表组件:

export class CompanyHistoryComponent implements OnInit {
  @ViewChild('tableInput') tableInput: ElementRef;
  @Input() companyId = 0;
  private rows: Observable<Array<any>>;
  // public rows: any[] = [];

  resultsLength: number;
  dataSource: ListDataSource<any> | null;
  database: ListDatabase<any>;
  tableHover = true;
  tableStriped = true;
  tableCondensed = true;
  tableBordered = true;

  constructor(
    public sensorService: SensorService,
    public dashboardService: DashboardService,
    private cd: ChangeDetectorRef,
  ) {
    // Selected company changed
    this.dashboardService.onCompanyChange.subscribe(
      (id: number) => {
        this.companyId = id;
        this.loadSensorHistory();
        cd.detectChanges();
      });
  }

  public loadSensorHistory() {
    const sDate: Number = moment().subtract(30, 'day').unix()
    const eDate: Number = moment().unix();

    this.sensorService.getSensorDataHistory(this.companyId, sDate, eDate, null, null, 1, 10).subscribe(response => {
      if (response.statusCode !== 200 || !response.data) {
        // this.toastrService.error('MESSAGE.NO_DATA', 'SENSOR_FORM_LIST.TITLE', { positionClass: 'toast-top-right', closeButton: true });
      } else {
        this.rows = response.data.list;
      }
    });
  }
  ngOnInit() {

  }


正如你所看到的,这次我添加了detectChanges(),但没有任何结果:(如果你有想法,请告诉我。这是表格的HTML:

<table class="table" [class.table-hover]="tableHover" [class.table-striped]="tableStriped" [class.table-condensed]="tableCondensed"
  [class.table-bordered]="tableBordered">
  <thead>
    <tr>
      <th>Date</th>
      <th>Device</th>
      <th>Sensor</th>
      <th>Value</th>
    </tr>
  </thead>
  <tbody>
    <tr *ngFor="let row of rows" [class.row-failed]="row.failed > 0">
      <td>{{ row.data_createdDate | date:'MM/dd/yyyy HH:mm:ss a Z' }}</td>
      <td>
        <a href="">{{ row.deviceMAC }}</a>
      </td>
      <td>
        <a href="">{{ row.sensorNumber }} - {{ row.sensorName }}</a>
      </td>
      <td>{{ row.value }}</td>
    </tr>
  </tbody>
</table>

rqqzpn5f

rqqzpn5f1#

应该调用ChangeDetectorRef detectChanges()

zvokhttg

zvokhttg2#

这可能是一个不正确的管道操作符。我在Angular 11和mat-table上也遇到了类似的问题。直到我盘旋在它们上面,它们才显现出来。我的问题是我在其中一列上使用了无效的管道操作符。我在字符串列上使用十进制管道。一旦我纠正了它的工作完美。

68bkxrlz

68bkxrlz3#

在构造函数中添加private cd: ChangeDetectorRef,并在数据更新的特定变量之后调用this.cd.detectChanges();
例如,在ngFor中使用变量additionalPropertiesForDisplay,其中数据不会在屏幕上悬停或单击操作时呈现

因此,调用更改检测器,如下图所示,使数据在页面加载时加载,而无需等待屏幕上发生悬停或单击事件

相关问题