2017-09-20 14:11:22 +03:00
|
|
|
|
import { Component, AfterViewInit, OnDestroy } from '@angular/core';
|
2017-08-01 17:42:21 +03:00
|
|
|
|
import { NbThemeService } from '@nebular/theme';
|
2017-07-26 19:59:47 +03:00
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
|
selector: 'ngx-echarts-multiple-xaxis',
|
2017-07-27 12:06:50 +03:00
|
|
|
|
template: `
|
|
|
|
|
|
<div echarts [options]="options" class="echart"></div>
|
|
|
|
|
|
`,
|
2017-07-26 19:59:47 +03:00
|
|
|
|
})
|
2017-09-20 14:11:22 +03:00
|
|
|
|
export class EchartsMultipleXaxisComponent implements AfterViewInit, OnDestroy {
|
2017-08-28 13:34:21 +03:00
|
|
|
|
options: any = {};
|
2017-09-20 14:11:22 +03:00
|
|
|
|
themeSubscription: any;
|
2017-07-27 12:06:50 +03:00
|
|
|
|
|
2017-08-01 17:42:21 +03:00
|
|
|
|
constructor(private theme: NbThemeService) {
|
2017-08-28 13:34:21 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ngAfterViewInit() {
|
2017-09-20 14:11:22 +03:00
|
|
|
|
this.themeSubscription = this.theme.getJsTheme().subscribe(config => {
|
2017-08-01 15:42:06 +03:00
|
|
|
|
|
2017-08-28 13:34:21 +03:00
|
|
|
|
const colors: any = config.variables;
|
2017-08-01 15:42:06 +03:00
|
|
|
|
const echarts: any = config.variables.echarts;
|
2017-07-27 12:06:50 +03:00
|
|
|
|
|
2017-07-27 17:21:38 +03:00
|
|
|
|
this.options = {
|
2017-08-01 15:42:06 +03:00
|
|
|
|
backgroundColor: echarts.bg,
|
2017-08-28 13:34:21 +03:00
|
|
|
|
color: [colors.success, colors.info],
|
2017-07-27 17:21:38 +03:00
|
|
|
|
tooltip: {
|
|
|
|
|
|
trigger: 'none',
|
|
|
|
|
|
axisPointer: {
|
|
|
|
|
|
type: 'cross',
|
2017-07-27 12:06:50 +03:00
|
|
|
|
},
|
|
|
|
|
|
},
|
2017-07-27 17:21:38 +03:00
|
|
|
|
legend: {
|
|
|
|
|
|
data: ['2015 Precipitation', '2016 Precipitation'],
|
|
|
|
|
|
textStyle: {
|
2017-08-28 13:34:21 +03:00
|
|
|
|
color: echarts.textColor,
|
2017-07-27 12:06:50 +03:00
|
|
|
|
},
|
|
|
|
|
|
},
|
2017-07-27 17:21:38 +03:00
|
|
|
|
grid: {
|
|
|
|
|
|
top: 70,
|
|
|
|
|
|
bottom: 50,
|
2017-07-27 12:06:50 +03:00
|
|
|
|
},
|
2017-07-27 17:21:38 +03:00
|
|
|
|
xAxis: [
|
|
|
|
|
|
{
|
|
|
|
|
|
type: 'category',
|
|
|
|
|
|
axisTick: {
|
|
|
|
|
|
alignWithLabel: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
axisLine: {
|
|
|
|
|
|
onZero: false,
|
|
|
|
|
|
lineStyle: {
|
2017-08-28 13:34:21 +03:00
|
|
|
|
color: colors.info,
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
axisLabel: {
|
|
|
|
|
|
textStyle: {
|
|
|
|
|
|
color: echarts.textColor,
|
2017-07-27 17:21:38 +03:00
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
axisPointer: {
|
|
|
|
|
|
label: {
|
|
|
|
|
|
formatter: params => {
|
|
|
|
|
|
return (
|
|
|
|
|
|
'Precipitation ' + params.value + (params.seriesData.length ? ':' + params.seriesData[0].data : '')
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
data: [
|
|
|
|
|
|
'2016-1',
|
|
|
|
|
|
'2016-2',
|
|
|
|
|
|
'2016-3',
|
|
|
|
|
|
'2016-4',
|
|
|
|
|
|
'2016-5',
|
|
|
|
|
|
'2016-6',
|
|
|
|
|
|
'2016-7',
|
|
|
|
|
|
'2016-8',
|
|
|
|
|
|
'2016-9',
|
|
|
|
|
|
'2016-10',
|
|
|
|
|
|
'2016-11',
|
|
|
|
|
|
'2016-12',
|
|
|
|
|
|
],
|
2017-07-27 12:06:50 +03:00
|
|
|
|
},
|
2017-07-27 17:21:38 +03:00
|
|
|
|
{
|
|
|
|
|
|
type: 'category',
|
|
|
|
|
|
axisTick: {
|
|
|
|
|
|
alignWithLabel: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
axisLine: {
|
|
|
|
|
|
onZero: false,
|
|
|
|
|
|
lineStyle: {
|
2017-08-28 13:34:21 +03:00
|
|
|
|
color: colors.success,
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
axisLabel: {
|
|
|
|
|
|
textStyle: {
|
|
|
|
|
|
color: echarts.textColor,
|
2017-07-27 17:21:38 +03:00
|
|
|
|
},
|
2017-07-27 12:06:50 +03:00
|
|
|
|
},
|
2017-07-27 17:21:38 +03:00
|
|
|
|
axisPointer: {
|
|
|
|
|
|
label: {
|
|
|
|
|
|
formatter: params => {
|
|
|
|
|
|
return (
|
|
|
|
|
|
'Precipitation ' + params.value + (params.seriesData.length ? ':' + params.seriesData[0].data : '')
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
data: [
|
|
|
|
|
|
'2015-1',
|
|
|
|
|
|
'2015-2',
|
|
|
|
|
|
'2015-3',
|
|
|
|
|
|
'2015-4',
|
|
|
|
|
|
'2015-5',
|
|
|
|
|
|
'2015-6',
|
|
|
|
|
|
'2015-7',
|
|
|
|
|
|
'2015-8',
|
|
|
|
|
|
'2015-9',
|
|
|
|
|
|
'2015-10',
|
|
|
|
|
|
'2015-11',
|
|
|
|
|
|
'2015-12',
|
|
|
|
|
|
],
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
yAxis: [
|
|
|
|
|
|
{
|
|
|
|
|
|
type: 'value',
|
|
|
|
|
|
axisLine: {
|
|
|
|
|
|
lineStyle: {
|
2017-08-28 13:34:21 +03:00
|
|
|
|
color: echarts.axisLineColor,
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
splitLine: {
|
|
|
|
|
|
lineStyle: {
|
|
|
|
|
|
color: echarts.splitLineColor,
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
axisLabel: {
|
|
|
|
|
|
textStyle: {
|
|
|
|
|
|
color: echarts.textColor,
|
2017-07-27 17:21:38 +03:00
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
series: [
|
|
|
|
|
|
{
|
|
|
|
|
|
name: '2015 Precipitation',
|
|
|
|
|
|
type: 'line',
|
|
|
|
|
|
xAxisIndex: 1,
|
|
|
|
|
|
smooth: true,
|
|
|
|
|
|
data: [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3],
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: '2016 Precipitation',
|
|
|
|
|
|
type: 'line',
|
|
|
|
|
|
smooth: true,
|
|
|
|
|
|
data: [3.9, 5.9, 11.1, 18.7, 48.3, 69.2, 231.6, 46.6, 55.4, 18.4, 10.3, 0.7],
|
2017-07-27 12:06:50 +03:00
|
|
|
|
},
|
|
|
|
|
|
],
|
2017-07-27 17:21:38 +03:00
|
|
|
|
};
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2017-09-20 14:11:22 +03:00
|
|
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
|
|
this.themeSubscription.unsubscribe();
|
|
|
|
|
|
}
|
2017-07-26 19:59:47 +03:00
|
|
|
|
}
|