<!-- Taryn Takebayashi -->
<!DOCTYPE html>
<html>
<head>
<title>XY Plotter</title>
<!-- The following link is what is used to include the
Chart.js functions
-->
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded',init);
//this function will clear all of the children of an element
function removeChildren(elem){
while(elem.childNodes.length > 0){
elem.removeChild(elem.childNodes[0]);
}
}
//this function obtains the user input data and
//calls the doChart() function to make the chart
function getDataAndPlot() {
let data1 = [];
const label = document.getElementById("label");
let label1 = label.value.trim();
const myChart = document.getElementById("myChart");
removeChildren(myChart);
const textarea = document.getElementById("textarea");
let xydata = textarea.value.split("\n");
//console.log(xydata);
for (let i = 0; i < xydata.length; i++) {
let splitValue = xydata[i].split(",");
let row = {};
row["x"] = Number(splitValue[0]);
row["y"] = Number(splitValue[1]);
data1.push(row);
}
//console.log(data1);
doChart(data1,label1);
}
function init() {
const run = document.getElementById("run");
run.addEventListener("click",getDataAndPlot);
}
//this doChart() function uses Chart.js to create a
//xy scatter chart
function doChart(data1,label1) {
let ctx =...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.