Browse Source

Sort outcome balance data for chart

tags/v0.1.3
bertieb 3 years ago
parent
commit
ef598d2c98
1 changed files with 12 additions and 3 deletions
  1. +12
    -3
      src/ts/frontend.ts

+ 12
- 3
src/ts/frontend.ts View File

@@ -118,7 +118,7 @@ function outcomesReport(rollstats: RollStats): string {
} }


function outcomeBalancesReport(rollstats: RollStats): string { function outcomeBalancesReport(rollstats: RollStats): string {
let output = subTitle("Outcome Balancess");
let output = subTitle("Outcome Balances");
// Preamble // Preamble


// Chart // Chart
@@ -185,14 +185,23 @@ function generateCharts(rollstats: RollStats): void {
* Outcome Balances * Outcome Balances
*/ */


let bc = rollstats.balanceCounts;
let keys = Object.keys(bc);
keys.sort(function(a: string, b: string){return Number(a) - Number(b)});
// sort values too
let values = [];
for (let i = 0; i < keys.length; i++) {
values.push(rollstats.balanceCounts[keys[i]]);
}

let balanceCanvas: any = $("#balanceChart"); let balanceCanvas: any = $("#balanceChart");
let balanceChart = new Chart(balanceCanvas, { let balanceChart = new Chart(balanceCanvas, {
type: "bar", type: "bar",
data: { data: {
labels: Object.keys(rollstats.balanceCounts),
labels: keys,
datasets: [{ datasets: [{
label: "Outcome Balance Counts", label: "Outcome Balance Counts",
data: Object.values(rollstats.balanceCounts),
data: values,
backgroundColor: hexColours(Object.values(rollstats.balanceCounts).length), backgroundColor: hexColours(Object.values(rollstats.balanceCounts).length),
}], }],
}, },


Loading…
Cancel
Save