I'm student with no programming experience, but for a project I need to get a txt file into my Javascript chart on the HTML web page. I already tried a lot but I just cant seem it to manage it. The txt file is local and in the same folder as the html. The txt file: [[0,8],[1,10],[2,14],[3,17],[4,13],[5,8],[6,8],[7,13],[8,10],[9,13],[10,14],[11,15],[11,15]]
In this code a chart is made with values of a website, but I need to get its values from a local txt file. I have no clue how to make this work. I hope someone can help to make the code work with local txt file. code
<!DOCTYPE HTML>
<html>
<head>
<script>
//chart
window.onload = function () {
var dataPoints = [];
var chart = new CanvasJS.Chart("chartContainer", {
theme: "light2",
title: {
text: "Live Data"
},
data: [{
type: "line",
dataPoints: dataPoints
}]
});
updateData();
// Initial Values
var xValue = 0;
var yValue = 10;
var newDataCount = 6;
function addData(data) {
if (newDataCount != 1) {
$.each(data, function (key, value) {
dataPoints.push({
x: value[0],
y: parseInt(value[1])
});
xValue++;
yValue = parseInt(value[1]);
});
} else {
//dataPoints.shift();
dataPoints.push({
x: data[0][0],
y: parseInt(data[0][1])
});
xValue++;
yValue = parseInt(data[0][1]);
}
newDataCount = 1;
chart.render();
setTimeout(updateData, 1500);
}
function updateData() {
$.getJSON("https://canvasjs.com/services/data/datapoints.php?xstart=" + xValue + "&ystart=" + yValue + "&length=" + newDataCount + "type=json", addData);
}
}
</script>
</head>
<body>
<div id="chartContainer" style="height: 370px; width: 100%;"></div>
<script src="https://canvasjs.com/assets/script/jquery-1.11.1.min.js"></script>
<script src="https://canvasjs.com/assets/script/jquery.canvasjs.min.js"></script>
</body>
</html>