我在我的Angular 应用程序中使用Highchart。
我想格式化一个Highcharts数据表,并将其与图表沿着导出为PDF。
在stackbliz复制了同样的东西。
https://stackblitz.com/edit/angular-ivy-u9zvps?file=src%2Fapp%2Fapp.component.ts
这里的PDF下载只包含图表。
我试图实现〈https://jsfiddle.net/Ld561nbt/4/>在官方Highchart页https://api.highcharts.com/highcharts/exporting.showTable?_ga=2.151177465.1965572452.1639477244-32713185.1637664871中提到的Angular ,但没有运气。
有人能给我建议如何在导出PDF中包含Highchart dataTable吗
.HTML内容
<div class="row">
<div class="col-md-4">
<div class="charts card mb-3">
<highcharts-chart
[Highcharts]="Highcharts"
[options]="chartofTop10Senders"
[(update)]="updateFlag"
[oneToOne]="true"
style="width: 100%; display: block; height: 220px;">
</highcharts-chart>
</div>
</div>
</div>
.TS
import { Component, VERSION } from '@angular/core';
import * as Highcharts from 'highcharts';
import HC_exporting from 'highcharts/modules/exporting';
import offlineExporting from 'highcharts/modules/offline-exporting';
import HC_Data from 'highcharts/modules/export-data';
HC_exporting(Highcharts);
offlineExporting(Highcharts);
HC_Data(Highcharts);
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
chartRef;
Highcharts: typeof Highcharts = Highcharts; // required
chartConstructor: string = 'chart'; // optional string, defaults to 'chart'
chartofTop10Senders: Highcharts.Options = {
chart: { renderTo: 'chartTop10Senders' },
lang: { noData: '' },
title: { text: 'Top 10 Senders', useHTML: false },
subtitle: { text: null },
credits: { enabled: false },
xAxis: { title: { text: 'Sender' }, categories: [], visible: false },
yAxis: { visible: false },
legend: { enabled: false },
series: [],
exporting: { showTable: true, allowHTML: true, enabled: true },
};
chartCallback: Highcharts.ChartCallbackFunction = function (chart) {
this.chartRef = chart;
}; // optional function, defaults to null
updateFlag: boolean = false; // optional boolean
oneToOneFlag: boolean = true; // optional boolean, defaults to false
alertAnalysisData: {
delivery_reach: { name: string; y: number }[];
senders: { name: string; y: number }[];
users: { name: string; y: number }[];
};
constructor() {}
ngOnInit() {
this.assigndata();
}
assigndata() {
this.alertAnalysisData = {
delivery_reach: [
{ name: 'Deliveries', y: 415 },
{ name: 'Alerts', y: 20 },
{ name: 'RecipientUsers', y: 118 },
{ name: 'RecipientGroups', y: 0 },
],
senders: [
{ name: 'Daniel', y: 14 },
{ name: 'Ebison', y: 3 },
{ name: 'ibrahim ', y: 2 },
{ name: 'Vela', y: 1 },
],
users: [
{ name: 'Sati', y: 17 },
{ name: 'Mobile', y: 17 },
{ name: 'ibrahim ', y: 17 },
{ name: 'Shan', y: 16 },
{ name: 'Vela', y: 16 },
{ name: 'Ebi', y: 15 },
{ name: 'Daniel', y: 14 },
{ name: 'Vela', y: 2 },
{ name: 'Vee', y: 1 },
{ name: 'Yoge', y: 1 },
{ name: 'Satish C', y: 1 },
{ name: 'Abtr', y: 1 },
],
};
this.updateChart();
}
updateChart() {
this.chartofTop10Senders.series[0] = {
type: undefined,
data: this.alertAnalysisData.delivery_reach,
};
this.updateFlag = true;
}
exportPDF() {
this.updateFlag = true;
(Highcharts as any).exportAlertSummary(
[, Highcharts.charts[Highcharts.charts.length - 1]],
{ type: 'application/pdf', filename: 'Alert Summary' }
);
}
}
1条答案
按热度按时间8ljdwjyq1#
jsfiddle使用技巧导出表的示例。添加表作为子标题,使其成为导出的一部分。
现场演示:https://jsfiddle.net/BlackLabel/5rwnsmz7/
在此部分,创建表并将其添加为副标题。
这段代码呈现图表,如果你想将表格和图表一起导出到pdf,你需要改变设置并显示图表。我删除了隐藏图表的代码,并保留图表的默认设置。