fixed download function
This commit is contained in:
parent
b578c53594
commit
b4642ce57a
1 changed files with 4 additions and 7 deletions
|
|
@ -171,29 +171,26 @@ d3.csv("PHSwithContinent.csv").then(function(data) {
|
||||||
updateChart();
|
updateChart();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Download chart as PNG
|
|
||||||
d3.select("#downloadButton").on("click", function() {
|
d3.select("#downloadButton").on("click", function() {
|
||||||
const c = d3.select("#continentSelect").property("value");
|
const c = d3.select("#continentSelect").property("value");
|
||||||
const s = d3.select("#sexSelect").property("value");
|
const s = d3.select("#sexSelect").property("value");
|
||||||
const e = d3.select("#incomeSelect").property("value");
|
const e = d3.select("#incomeSelect").property("value");
|
||||||
|
|
||||||
const parts = [
|
const parts = [
|
||||||
"education_health",
|
"education_health",
|
||||||
c !== "All" ? c : null,
|
c !== "All" ? c : null,
|
||||||
s !== "All" ? s : null,
|
s !== "All" ? s : null,
|
||||||
e !== "All" ? e.replace(/[^a-zA-Z0-9]+/g, "_").toLowerCase() : null
|
e !== "All" ? e.replace(/[^a-zA-Z0-9]+/g, "_").toLowerCase() : null
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
|
|
||||||
const filename = parts.join("_") + ".png";
|
const filename = parts.join("_") + ".png";
|
||||||
|
|
||||||
saveSvgAsPng(document.getElementById("chart"), {
|
saveSvgAsPng(document.getElementById("chart"), filename, { // <-- filename second, options third
|
||||||
filename: filename,
|
|
||||||
scale: 2,
|
scale: 2,
|
||||||
backgroundColor: darkMode ? "#121212" : "#ffffff"
|
backgroundColor: darkMode ? "#121212" : "#ffffff"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update legend depending on chart type
|
// Update legend depending on chart type
|
||||||
function updateLegend(chartType) {
|
function updateLegend(chartType) {
|
||||||
const legend = d3.select("#legend");
|
const legend = d3.select("#legend");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue