Angular:如何在ng-template中显示模态对话框(图表)

问题描述 投票:0回答:1

我的应用程序将Angular 8与Bootstrap和chart.js结合使用。我试图在Angular ng-template指令中呈现引导弹出窗口。用户单击表格行的最后一列后,将立即显示弹出窗口(图形)。但是,正如您在图片上所看到的,背景是白色的,只有实际图形的一半。我如何摆脱这种背景?

html部分

    <tbody>
      <tr *ngFor="let stock of stockList; index as i" (click)="displaySelected(stock);">
        <td style="width: 30px" scope="row">{{ i + 1 }}</td>
        <td style="width: 40px">{{ stock.id }}</td>
        <td style="width: 70px">{{ stock.symbol }}</td>
        <td style="width: 70px">{{ stock.isin }}</td>
        <td style="width: 180px">{{ stock.name }}</td>
        <td style="width: 40px">{{ stock.liquid }}</td>
        <td [class]="getFlagClass(stock.countryCode)" style="width: 14px"></td>
        <td style="width: 180px">{{ stock.exchangeName }}</td>
        <td style="width: 180px">{{ stock.sector }}</td>
        <td style="width: 50px">{{ stock.active }}</td>
        <td style="width: 30px"><img src="assets/img/chart.png"  height="30" width="30" (click)="displayChart(content, stock);"/></td>
      </tr>
    </tbody>

  </table>

</div>


<ng-template #content let-modal>

      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">[name]</h5>
            <button type="button" class="close" aria-label="Close" (click)="modal.dismiss('Cross click')">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
              <canvas id="myChart" width="1000" height="500"></canvas>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-outline-dark" (click)="modal.close('Save click')">any action</button>
          </div>
        </div>
      </div>

</ng-template>

组成部分

  displayChart(content, stock: Istock) {

        // Open popup window
        this.modalService.open(content, {ariaLabelledBy: 'modal-basic-title'}).result.then((result) => {
          this.closeResult = `Closed with: ${result}`;
        }, (reason) => {
          this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
        });

        const today = new Date();
        const dd = today.getDate();
        const mm = today.getMonth();
        const yyyy = today.getFullYear();

        const dateTo: Date = new Date(yyyy, mm, dd);
        const dateFrom: Date = new Date(yyyy - 1, mm, dd);


        // retrieve dates and Prices
        this.labelsDate = new Array();
        this.dataPrices  = new Array();
        this.http.post(this.apiUrl + '/instrument/getPrices', {id: stock.id, from: dateFrom, to: dateTo } ).subscribe( (result: IinstrumentPrice[]) => {
            result.forEach(x => {
              this.labelsDate.push(x.date);
              this.dataPrices.push(x.close);
          });

          this.canvas = document.getElementById('myChart');
          this.ctx = this.canvas.getContext('2d');

          // display chart
          const myChart = new Chart(this.ctx, {
              type: 'line',
              data: {
                labels: this.labelsDate,
                datasets: [{
                  label: 'Daily prices',
                  data: this.dataPrices,
                  fill: false,
                  borderWidth: 2,
                  borderColor: 'black'
                }]
              },
              options: {
                elements: { point: { radius: 0 } },
                responsive: false,
                display: true
              }
          });
        });
  }

css部分

.row-input {
  font-size: 15px;
  padding-top: 2px;
  padding-right: 1px;
  padding-bottom: 1px;
  padding-left: 2px;
}

input {
  font-size: 15px;
}

.flag-us {
  background-size:contain;
  background-position:50%;
  background-repeat:no-repeat;
  position:relative;
  display:inline-block;
  width:1.33333333em;
  line-height:1em;
  background-image:url(../../assets/img/flags/united-states-of-america.png);
}

.modal-dialog{
  position: relative;
  display: table; /* This is important */
  overflow-y: auto;
  overflow-x: auto;
  width: auto;
  min-width: 300px;
}

enter image description here

css angular chart.js bootstrap-modal
1个回答
0
投票

解决方案是在open方法中设置参数{“ size:'xl'}

  displayChart(content, tableRow: TaPatternInstrumentResponseDto) {

    // Open popup window
    this.modalService.open(content, {size: 'xl'}).result.then((result) => {
© www.soinside.com 2019 - 2024. All rights reserved.