Plot
From Glioblastoma Treatments
Jump to navigationJump to search
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script> <script>
// Fetch the JSON data from the query result page fetch('https://glioblastomatreatments.wiki/index.php?title=Special:Ask/-5B-5BHas-20Usefulness-20Rating::%2B-5D-5D/-3FHas-20treatment-20name%3DTreatment-20Name/-3FHas-20Usefulness-20Rating%3DUsefulness-20Rating/-3FHas-20Toxicity-20Level%3DToxicity-20Level/-3FCategory/mainlabel%3D-2D/limit%3D100/offset%3D0/format%3Djson') .then(response => response.json()) .then(data => { const treatments = []; for (const [key, value] of Object.entries(data.results)) { treatments.push({ treatment: value.printouts['Treatment Name'][0].fulltext, effectiveness: parseInt(value.printouts['Usefulness Rating'][0].fulltext), toxicity: parseInt(value.printouts['Toxicity Level'][0].fulltext), category: value.printouts['Category'][0].fulltext.replace('Category:', ) }); }
const categories = [...new Set(treatments.map(t => t.category))];
// Create checkboxes for categories const categoriesDiv = document.getElementById('categories'); categories.forEach(category => { const label = document.createElement('label'); const checkbox = document.createElement('input'); checkbox.type = 'checkbox'; checkbox.value = category; checkbox.checked = true; checkbox.addEventListener('change', updatePlot); label.appendChild(checkbox); label.appendChild(document.createTextNode(category)); categoriesDiv.appendChild(label); });
// Initial plot updatePlot();
function updatePlot() { const selectedCategories = Array.from(document.querySelectorAll('#categories input[type="checkbox"]:checked')).map(cb => cb.value);
const filteredTreatments = treatments.filter(t => selectedCategories.includes(t.category));
const trace = { x: filteredTreatments.map(t => t.effectiveness), y: filteredTreatments.map(t => t.toxicity), mode: 'markers', type: 'scatter', text: filteredTreatments.map(t => t.treatment), marker: { color: filteredTreatments.map(t => categories.indexOf(t.category)) } };
const layout = { title: 'Glioblastoma Treatments', xaxis: { title: 'Effectiveness' }, yaxis: { title: 'Toxicity', autorange: 'reversed' } };
Plotly.newPlot('plot', [trace], layout); } }) .catch(error => console.error('Error fetching data:', error));
</script>