Skip to content

Commit

Permalink
Fixed #9961 - Update Chart Demos
Browse files Browse the repository at this point in the history
  • Loading branch information
yigitfindikli committed Mar 3, 2021
1 parent eae676d commit 8ef9657
Show file tree
Hide file tree
Showing 5 changed files with 322 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/app/showcase/components/chart/barchart/barchartdemo.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ <h1>BarChart</h1>

<div class="content-section implementation">
<div class="card">
<h5>Vertical</h5>
<p-chart type="bar" [data]="basicData" [options]="basicOptions"></p-chart>
</div>

<div class="card">
<h5>Horizontal</h5>
<p-chart type="horizontalBar" [data]="basicData" [options]="basicOptions"></p-chart>
</div>

<div class="card">
<h5>Multi Axis</h5>
<p-chart type="bar" [data]="multiAxisData" [options]="multiAxisOptions"></p-chart>
</div>

Expand All @@ -33,14 +36,17 @@ <h5>Stacked</h5>
</a>
<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;div class="card"&gt;
&lt;h5&gt;Vertical&lt;/h5&gt;
&lt;p-chart type="bar" [data]="basicData" [options]="basicOptions"&gt;&lt;/p-chart&gt;
&lt;/div&gt;

&lt;div class="card"&gt;
&lt;h5&gt;Horizontal&lt;/h5&gt;
&lt;p-chart type="horizontalBar" [data]="basicData" [options]="basicOptions"&gt;&lt;/p-chart&gt;
&lt;/div&gt;

&lt;div class="card"&gt;
&lt;h5&gt;Multi Axis&lt;/h5&gt;
&lt;p-chart type="bar" [data]="multiAxisData" [options]="multiAxisOptions"&gt;&lt;/p-chart&gt;
&lt;/div&gt;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {BarChartDemo} from './barchart/barchartdemo';
import {LineChartDemo} from './linechart/linechartdemo';
import {PolarAreaChartDemo} from './polarareachart/polarareachartdemo';
import {RadarChartDemo} from './radarchart/radarchartdemo';
import {ComboChartDemo} from './combochart/comobochartdemo';

@NgModule({
imports: [
Expand All @@ -17,7 +18,8 @@ import {RadarChartDemo} from './radarchart/radarchartdemo';
{path:'bar', component: BarChartDemo},
{path:'line', component: LineChartDemo},
{path:'polararea',component: PolarAreaChartDemo},
{path:'radar', component: RadarChartDemo}
{path:'radar', component: RadarChartDemo},
{path:'combo', component: ComboChartDemo}
])
],
exports: [
Expand Down
2 changes: 2 additions & 0 deletions src/app/showcase/components/chart/chartdemo.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {DoughnutChartDemo} from './doughnutchart/doughnutchartdemo';
import {BarChartDemo} from './barchart/barchartdemo';
import {LineChartDemo} from './linechart/linechartdemo';
import {PolarAreaChartDemo} from './polarareachart/polarareachartdemo';
import {ComboChartDemo} from './combochart/comobochartdemo';
import {RadarChartDemo} from './radarchart/radarchartdemo';
import {ChartModule} from 'primeng/chart';
import {ToastModule} from 'primeng/toast';
Expand All @@ -29,6 +30,7 @@ import {AppCodeModule} from '../../app.code.component';
BarChartDemo,
LineChartDemo,
PolarAreaChartDemo,
ComboChartDemo,
RadarChartDemo
]
})
Expand Down
166 changes: 166 additions & 0 deletions src/app/showcase/components/chart/combochart/combochartdemo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
<div class="content-section introduction">
<div class="feature-intro">
<h1>Combo Chart</h1>
<p>Different chart types can be combined in the same graph.</p>
</div>
</div>

<div class="content-section implementation">
<div class="card">
<p-chart type="bar" [data]="data" [options]="chartOptions"></p-chart>
</div>
</div>

<div class="content-section documentation">


<p-tabView>
<p-tabPanel header="Source">
<a href="https://github.com/primefaces/primeng/tree/master/src/app/showcase/components/chart/doughnutchart" class="btn-viewsource" target="_blank">
<span>View on GitHub</span>
</a>
<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-chart type="bar" [data]="data" [options]="chartOptions"&gt;&lt;/p-chart&gt;
</app-code>
<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
export class DoughnutChartDemo &#123;

data: any;

chartOptions: any;

subscription: Subscription;

config: AppConfig;

constructor(private configService: AppConfigService) &#123;&#125;

ngOnInit() &#123;
this.data = &#123;
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [&#123;
type: 'line',
label: 'Dataset 1',
borderColor: '#42A5F5',
borderWidth: 2,
fill: false,
data: [
50,
25,
12,
48,
56,
76,
42
]
&#125;, &#123;
type: 'bar',
label: 'Dataset 2',
backgroundColor: '#66BB6A',
data: [
21,
84,
24,
75,
37,
65,
34
],
borderColor: 'white',
borderWidth: 2
&#125;, &#123;
type: 'bar',
label: 'Dataset 3',
backgroundColor: '#FFA726',
data: [
41,
52,
24,
74,
23,
21,
32
]
&#125;]
&#125;;
this.chartOptions = &#123;
responsive: true,
title: &#123;
display: true,
text: 'Combo Bar Line Chart'
&#125;,
tooltips: &#123;
mode: 'index',
intersect: true
&#125;
&#125;;

this.config = this.configService.config;
this.updateChartOptions();
this.subscription = this.configService.configUpdate$.subscribe(config =&gt; &#123;
this.config = config;
this.updateChartOptions();
&#125;);
&#125;

updateChartOptions() &#123;
if (this.config.dark)
this.applyDarkTheme();
else
this.applyLightTheme();
&#125;

applyLightTheme() &#123;
this.chartOptions = &#123;
legend: &#123;
labels: &#123;
fontColor: '#495057'
&#125;
&#125;,
scales: &#123;
xAxes: [&#123;
ticks: &#123;
fontColor: '#495057'
&#125;
&#125;],
yAxes: [&#123;
ticks: &#123;
fontColor: '#495057'
&#125;
&#125;]
&#125;
&#125;
&#125;

applyDarkTheme() &#123;
this.chartOptions = &#123;
legend: &#123;
labels: &#123;
fontColor: '#ebedef'
&#125;
&#125;,
scales: &#123;
xAxes: [&#123;
ticks: &#123;
fontColor: '#ebedef'
&#125;,
gridLines: &#123;
color: 'rgba(255,255,255,0.2)'
&#125;
&#125;],
yAxes: [&#123;
ticks: &#123;
fontColor: '#ebedef'
&#125;,
gridLines: &#123;
color: 'rgba(255,255,255,0.2)'
&#125;
&#125;]
&#125;
&#125;;
&#125;
&#125;
</app-code>
</p-tabPanel>
</p-tabView>
</div>
145 changes: 145 additions & 0 deletions src/app/showcase/components/chart/combochart/comobochartdemo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import {Component, OnInit} from '@angular/core';
import {Subscription} from 'rxjs';
import {AppConfigService} from '../../../service/appconfigservice';
import {AppConfig} from '../../../domain/appconfig';

@Component({
templateUrl: './combochartdemo.html'
})
export class ComboChartDemo {

data: any;

chartOptions: any;

subscription: Subscription;

config: AppConfig;

constructor(private configService: AppConfigService) {}

ngOnInit() {
this.data = {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [{
type: 'line',
label: 'Dataset 1',
borderColor: '#42A5F5',
borderWidth: 2,
fill: false,
data: [
50,
25,
12,
48,
56,
76,
42
]
}, {
type: 'bar',
label: 'Dataset 2',
backgroundColor: '#66BB6A',
data: [
21,
84,
24,
75,
37,
65,
34
],
borderColor: 'white',
borderWidth: 2
}, {
type: 'bar',
label: 'Dataset 3',
backgroundColor: '#FFA726',
data: [
41,
52,
24,
74,
23,
21,
32
]
}]
};
this.chartOptions = {
responsive: true,
title: {
display: true,
text: 'Combo Bar Line Chart'
},
tooltips: {
mode: 'index',
intersect: true
}
};

this.config = this.configService.config;
this.updateChartOptions();
this.subscription = this.configService.configUpdate$.subscribe(config => {
this.config = config;
this.updateChartOptions();
});
}

updateChartOptions() {
if (this.config.dark)
this.applyDarkTheme();
else
this.applyLightTheme();
}

applyLightTheme() {
this.chartOptions = {
legend: {
labels: {
fontColor: '#495057'
}
},
scales: {
xAxes: [{
ticks: {
fontColor: '#495057'
}
}],
yAxes: [{
ticks: {
fontColor: '#495057'
}
}]
}
}
}

applyDarkTheme() {
this.chartOptions = {
legend: {
labels: {
fontColor: '#ebedef'
}
},
scales: {
xAxes: [{
ticks: {
fontColor: '#ebedef'
},
gridLines: {
color: 'rgba(255,255,255,0.2)'
}
}],
yAxes: [{
ticks: {
fontColor: '#ebedef'
},
gridLines: {
color: 'rgba(255,255,255,0.2)'
}
}]
}
};
}
}

0 comments on commit 8ef9657

Please sign in to comment.