【发布时间】:2018-04-09 02:00:05
【问题描述】:
我正在尝试从 htmltable 创建一个 highchart 饼图,但它没有被创建 我已经从this url 安装了 highchart。使用系列数据 highchart 运行良好。但是一旦我尝试从 html 表中选择数据。它没有形成。我也尝试过不显示任何 html 表,但它仍然无法正常工作。请建议在这种情况下该怎么做。
下面是模板代码:
<div class="highcart_div" #highcart_div style="height: 200px; width: 100%;"></div>
<table id="datatable" #datatable style="display: none;">
<tbody>
<tr>
<th>Apples</th>
<td>3</td>
<td>4</td>
</tr>
<tr>
<th>Pears</th>
<td>2</td>
<td>0</td>
</tr>
<tr>
<th>Plums</th>
<td>5</td>
<td>11</td>
</tr>
<tr>
<th>Bananas</th>
<td>1</td>
<td>1</td>
</tr>
<tr>
<th>Oranges</th>
<td>2</td>
<td>4</td>
</tr>
</tbody>
</table>
下面是组件代码:
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { chart } from "highcharts";
import * as Highcharts from 'highcharts';
@Component({
selector: 'app-analytics-content',
templateUrl: './analytics-content.component.html',
styleUrls: ['./analytics-content.component.css']
})
export class AnalyticsContentComponent implements OnInit {
chart: Highcharts.ChartObject;
@ViewChild("highcart_div") chartTarget: ElementRef;
@ViewChild("datatable") datatable: ElementRef;
constructor() { }
ngOnInit() {
}
ngAfterViewInit() {
const options: Highcharts.Options = {
data: {
table: this.datatable.nativeElement
},
chart: {
type: 'pie'
},
title: {
text: ''
},
yAxis: {
allowDecimals: false,
title: {
text: 'Units'
}
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false,
},
innerSize: '60%'
}
},
tooltip: {
formatter: function () {
return '<b>'
+ this.series.name
+ '</b><br/>'
+ this.point.y
+ ' '
+ this.point.name
.toLowerCase();
}
}
};
this.chart = chart(this.chartTarget.nativeElement, options);
}
}
【问题讨论】:
标签: angular highcharts angular5