Skip to content

Commit 97ae29c

Browse files
committed
Try to increase width of categories image to have room for mopre categories being displayed. Also sort categories by count before displaying
1 parent 23ec9e0 commit 97ae29c

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

app/server.js

+22-10
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,18 @@ async function generateIncByWeekChart(numberOfDays) {
237237
},
238238
},
239239
});
240-
chart.setWidth(800);
241-
chart.setHeight(400);
242-
return chart.getUrl();
240+
// Increase chart size
241+
chart.setWidth(400);
242+
chart.setHeight(200);
243+
return chart.getShortUrl();
243244
}
244245

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

248-
const labels = dbResponse.rows.map((row) => row.category);
249-
const data = dbResponse.rows.map((row) => parseInt(row.count, 10));
250+
const labels = sortedCategories.map((row) => row.category);
251+
const data = sortedCategories.map((row) => parseInt(row.count, 10));
250252

251253
// Generate the bar chart URL using QuickChart
252254
const chart = new QuickChart();
@@ -266,13 +268,23 @@ async function generateIncByCategoryChart(numberOfDays) {
266268
},
267269
options: {
268270
scales: {
269-
y: {
270-
beginAtZero: true,
271+
xAxes: {
272+
ticks: {
273+
max: labels.length, // Limit the number of labels to show
274+
},
275+
},
276+
yAxes: {
277+
ticks: {
278+
beginAtZero: true, // Start the y-axis at 0
279+
stepSize: 1, // Set the step size to 1
280+
}
271281
},
272282
},
273283
},
274284
});
275-
chart.setWidth(800);
276-
chart.setHeight(400);
277-
return chart.getUrl();
285+
286+
// Increase chart size
287+
chart.setWidth(400);
288+
chart.setHeight(200);
289+
return chart.getShortUrl();
278290
}

0 commit comments

Comments
 (0)