Skip to content

Commit

Permalink
Try to increase width of categories image to have room for mopre cate…
Browse files Browse the repository at this point in the history
…gories being displayed. Also sort categories by count before displaying
  • Loading branch information
Sinan-96 committed Oct 3, 2024
1 parent 23ec9e0 commit d7a5b03
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions app/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,18 @@ async function generateIncByWeekChart(numberOfDays) {
},
},
});
chart.setWidth(800);
chart.setHeight(400);
return chart.getUrl();
// Increase chart size
chart.setWidth(900);
chart.setHeight(600);
return chart.getShortUrl();
}

async function generateIncByCategoryChart(numberOfDays) {
const dbResponse = await getIncByCategory(numberOfDays);
const sortedCategories = dbResponse.rows.sort((a, b) => b.count - a.count);

const labels = dbResponse.rows.map((row) => row.category);
const data = dbResponse.rows.map((row) => parseInt(row.count, 10));
const labels = sortedCategories.map((row) => row.category);
const data = sortedCategories.map((row) => parseInt(row.count, 10));

// Generate the bar chart URL using QuickChart
const chart = new QuickChart();
Expand All @@ -266,13 +268,25 @@ async function generateIncByCategoryChart(numberOfDays) {
},
options: {
scales: {
x: {
ticks: {
autoSkip: false, // Disable auto-skip for labels to show all categories
maxTicksLimit: labels.length, // Limit the number of labels to show
},
},
y: {
beginAtZero: true,
beginAtZero: true, // Ensure Y-axis starts at zero
min: 0, // Ensure Y-axis starts at zero
ticks: {
padding: 10, // Increase space for tick labels
},
},
},
},
});
chart.setWidth(800);
chart.setHeight(400);
return chart.getUrl();

// Increase chart size
chart.setWidth(900);
chart.setHeight(600);
return chart.getShortUrl();
}

0 comments on commit d7a5b03

Please sign in to comment.