我想在我的角度上制作一个带有Highchart的图表,但由于在Highchart的官方网站上缺乏关于Angular中Highchart使用的信息,我不得不使用它。
这是queue-dashboard.component.ts上的高级图书馆:
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { CountryunitService } from '../../countryunit.service';
import * as Highcharts from 'highcharts';
import { Injectable } from '@angular/core';
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http';
import { map } from 'lodash';
这是ngOnInit()
queue-dashboard.component.ts中的内容
ngOnInit() {
var chart = Highcharts.chart('container', {
title: {
text: 'Chart.update'
},
subtitle: {
text: 'Plain'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
type: 'column',
colorByPoint: true,
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
showInLegend: false
}]
});
如果要调用此队列中的图表 - dashboard.component.html,我该怎么办?
<div eds-tile class="xl-6" style="height: 350px">
<eds-tile-title>Count of Ticket ID by CU ID</eds-tile-title>
<!-- Highchart On This -->
</div>
有多种方法可以使用HTML呈现图表。将尝试解释其中的一些
1.我们可以通过在图表配置对象中指定元素名称来渲染元素上的图表。因此,假设您要在HTML文件中提到的div上呈现图表。
<div eds-tile class="xl-6" style="height: 350px">
<eds-tile-title>Count of Ticket ID by CU ID</eds-tile-title>
<div id="chartContainer"></div>
<!-- Highchart On This -->
</div>
您可以通过在元素上呈现来配置图表对象
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { CountryunitService } from '../../countryunit.service';
import * as Highcharts from 'highcharts';
import { Injectable } from '@angular/core';
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http';
import { map } from 'lodash';
导出类YourComponentName实现OnInit {
setTimeout( ()=>{
this.Highcharts.chart({
chart: {
type: 'column',
renderTo:'chartContainer',
},
title: {
text: 'Chart.update'
},
subtitle: {
text: 'Plain'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
type: 'column',
colorByPoint: true,
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
showInLegend: false
}]
})},3000);
this.chartConfig = {
title: {
text: 'Chart.update'
},
subtitle: {
text: 'Plain'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
type: 'column',
colorByPoint: true,
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
showInLegend: false
}]
}
在您的HTMl中,您可以动态绑定图表(指令)
<div eds-tile class="xl-6" style="height: 350px">
<eds-tile-title>Count of Ticket ID by CU ID</eds-tile-title>
<div id="chartContainer">
<chart [options]="chartConfig"></chart>
</div>
<!-- Highchart On This -->
</div>
可能有可能没有取高度和宽度的高图的css。要添加,你可以在你的组件css / scss中添加这个css。
chart {
width: 100% !important;
margin: 0 auto;
display: block;
}
.highcharts-root {
width: 100% !important;
display: block;
}
.highcharts-container {
width: 100% !important;
}