You must be logged in to post your query.
Home › Forums › Chart Support › PLOT Graph using txt
Tagged: line graph Plot
Hello I want to create a graph with txt source. The example in txt file is this
YR MON TOTAL ClimAdjust ANOM 1950 1 24.56 26.18 -1.62 1950 2 25.07 26.39 -1.32 1950 3 25.88 26.95 -1.07 1950 4 26.29 27.39 -1.11 1950 5 26.19 27.56 -1.37 1950 6 26.47 27.21 -0.74 1950 7 26.28 26.72 -0.44 1950 8 25.88 26.30 -0.42 1950 9 25.73 26.14 -0.41 1950 10 25.68 26.01 -0.32 1950 11 25.46 26.06 -0.60 1950 12 25.29 26.18 -0.88 1951 1 25.26 26.18 -0.92 1951 2 25.72 26.39 -0.66 1951 3 26.91 26.95 -0.04 1951 4 27.59 27.39 0.20 1951 5 27.93 27.56 0.37 1951 6 27.73 27.21 0.52 1951 7 27.59 26.72 0.87 1951 8 27.01 26.30 0.71 1951 9 27.22 26.14 1.08 1951 10 27.20 26.01 1.19 1951 11 27.25 26.06 1.19 1951 12 26.92 26.18 0.74 1952 1 26.67 26.18 0.49 1952 2 26.75 26.39 0.37 1952 3 27.19 26.95 0.24 1952 4 27.81 27.39 0.42 1952 5 27.79 27.56 0.23 1952 6 27.18 27.21 -0.03
I want this to plot as graph output but IF theres a negative value, it will also plot as graphs but opposite heres the example graph I want it look like http://www.pimohweather.com/elninolanina.php
I hope you can hemp me create my own graph menyioned above sample TY
@pimohdaimaoh,
You need to parse the text file to the format accepted by CanvasJS. Please take a look at this below code snippet for the same.
function handleFiles() { var fileList = this.files; var reader = new FileReader(); reader.readAsText(fileList[0]); reader.onload = function() { renderChart(reader); } } function renderChart(reader) { var dpsList = reader.result; var dataPoint; var dps1= [], dps2 = [], dps3 = []; dpsList = dpsList.split("\n"); for(var i = 1; i < dpsList.length; i++) { var separateData = dpsList[i].split(" "); yVal = parseFloat(separateData[4]); xVal = new Date(parseInt(separateData[0]), parseInt(separateData[1])); chart.options.data[0].dataPoints.push({x: xVal, y: yVal}); chart.options.data[1].dataPoints.push({x: xVal, y: yVal}); } chart.render(); }
Also, check out this JSFiddle for complete working code.
—- Manoj Mohan Team CanvasJS
You must be logged in to reply to this topic. Login/Register