Skip to content

Commit

Permalink
economy rate chart fix and data label added
Browse files Browse the repository at this point in the history
  • Loading branch information
second-slip committed Aug 2, 2024
1 parent 829795c commit b020a8a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/app/data-fetch.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
import { IChartData } from './i-chart-data.dto';
import { cumulativeAverageData, cumulativeStrikeRateData, cumulativeEconomyData, wicketsByTeamData, ageAnalysisData, formatAnalysisData, wicketsPerMatch } from '../assets/chartData';
import { cumulativeAverageData, cumulativeStrikeRateData, cumulativeEconomyData, ageAnalysisData, formatAnalysisData, wicketsPerMatch } from '../assets/chartData';
import { wicketsByTeamData } from '../../dist/cricket-charts/browser/assets/chartData';

@Injectable({
providedIn: 'root'
Expand Down
3 changes: 2 additions & 1 deletion src/app/economy-rate/economy-rate.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@if (loaded()) {
<h4 class="centre">Economy rate</h4>
<p class="centre">James Anderson's economy rate is 2.79. This is how it changed over his career.</p>
<canvas class="chart" baseChart [type]="'line'" [legend]="true" [datasets]="bowlingEconomyData.datasets"
[labels]="bowlingEconomyData.labels" [options]="lineChartOptions">
[labels]="bowlingEconomyData.labels" [options]="lineChartOptions" [plugins]="chartPlugins">
</canvas>
}
17 changes: 17 additions & 0 deletions src/app/economy-rate/economy-rate.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ChartConfiguration, ChartData } from 'chart.js';
import { IChartData } from '../i-chart-data.dto';
import { BaseChartDirective } from 'ng2-charts';
import { DataFetchService } from '../data-fetch.service';
import ChartDataLabels from 'chartjs-plugin-datalabels';

@Component({
selector: 'app-economy-rate',
Expand All @@ -19,6 +20,7 @@ export class EconomyRateComponent {
this.chart?.chart?.resize();
}

public chartPlugins = [ChartDataLabels];
public loaded = signal(false);

public bowlingEconomyData: ChartData<'line'> = {
Expand All @@ -44,6 +46,9 @@ export class EconomyRateComponent {
next: (data: IChartData) => {
this.bowlingEconomyData.labels = data.chartLabels,
this.bowlingEconomyData.datasets[0].data = data.chartData[0]

console.log(this.bowlingEconomyData.labels.length)
console.log(this.bowlingEconomyData.datasets[0].data.length)
},
error: (e) => { console.log(e); }
});
Expand All @@ -58,6 +63,18 @@ export class EconomyRateComponent {
plugins: {
legend: {
position: 'bottom'
},
datalabels: {
borderRadius: 4,
color: 'black',
font: {
weight: 'bold'
},
padding: 6,
offset: 0,
align: 'top',
anchor: 'end',
formatter: (val, ctx) => ctx.dataIndex === this.bowlingEconomyData.datasets[0].data.length - 1 ? val : ''
}
},
scales: {
Expand Down
5 changes: 5 additions & 0 deletions src/app/ideas/ideas.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ <h3>Change log</h3>
<th style="width:85%">Change</th>
<th>Date</th>
</tr>
<tr>
<td>Fix applied to economy rate chart. Wrong data labels were in use.
</td>
<td>02/08/2024</td>
</tr>
<tr>
<td>Bowling average charts moved into a tabs group design.
</td>
Expand Down
Loading

0 comments on commit b020a8a

Please sign in to comment.