Home forums Using CanvasJS reading text files from any location in filesystem to plot graph

This topic contains 3 replies, has 2 voices, and was last updated by  Indranil Deo 2 months, 1 week ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #24570

    I have a folder to store the text files which is declared outside the server folder. How to read the contents of that text file which is located outside server folder using jQuery.

    Currently I am not able to read text files from jQuery.

    <tr>
    <td><input type=”checkbox” id=”par” name=”par” value=” <%=tempParam.getData()%>”></td>
    <td><%=tempParam.getParameter().toUpperCase()%></td>
    <td><%=tempParam.getDescription().toUpperCase()%></td>
    <td><%=tempParam.getMission().toUpperCase()%></td>
    <td><%=tempParam.getTelemetry().toUpperCase()%></td>
    </tr>
    <input class=”btn5″ type=”image” src=”images/images1.jpg” onclick=”javascript:graphplot()” name=”ok” title=”GRAPH PLOT” >
    javascript:

    function graphplot() {
    var param = [],
    nam = [];
    var out = [];
    var i, t = 0;
    var url, filename, ff, url1, string2, mn, telnm;
    var dataPointss = [],
    arr = [
    []
    ];
    var k = 3,
    n = 0,
    m = 0;
    $.each($j(‘#hd1’).DataTable().rows().nodes().to$().find(‘input[type=”checkbox”]:checked’), function() {
    url = $(this).val();
    url = url.replace(/\\/gi, “/”);
    filename = url.substring(url.lastIndexOf(“/”) + 1);
    filename = filename.substring(0, filename.lastIndexOf(“.”));
    ff = url.split(“/”).slice(7).join(“/”);
    param.push(url);
    });
    if (param.length <= 5 || param.length > 0) {
    for (n = 0; n < param.length; n++) {
    var reader = new FileReader();
    reader.onload = function(event) {
    var contents = event.target.result;
    alert(contents);
    var allx = contents.split(‘\n’);
    for (i = 3; i < allx.length; i++) {
    allx[i] = allx[i].trim();
    }
    k = 3;
    $.each(allx, function(k) {
    if (allx.length > 0) {
    var ally = allx[k].split(/ +/);
    chart.options.data[m].dataPoints.push({
    x: parseFloat(ally[0]),
    y: parseFloat(ally[1])
    });
    k++;
    }
    });
    chart.options.data[m].name = nam[m];
    chart.render();
    m++;
    };
    reader.readAsText(param[n]);
    }
    }
    }
    I expect a code help to read text file line by line and store in arraylist.

    #24590

    @rekharjun,

    Browsers doesn’t allow reading file from local machines due to security reasons. Please refer to this stackoverflow thread for more information.

    If the file is hosted on a server you can read it using jQuery AJAX request.

    ___________
    Indranil Deo,
    Team CanvasJS

    #24635

    can u help me to copy some selected files from one location to another location using jquery???

    #24639

    @rekharjun,

    Please take a look at this StackOverflow link for more info on moving a file from one directory to other using jQuery.

    Feel free to let us know if you have any queries related to CanvasJS.

    ___________
    Indranil Deo,
    Team CanvasJS

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.