Home forums Using CanvasJS two csv in the same chart

Tagged: 

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #23237

    HI,

    I want creating one chart with two CSV files.

    code js :

    $.ajax({
    type: “GET”,
    url: “test1.csv”,
    dataType: “text”,
    success: function (data) {
    processCSV1(data, “3000”, “3000”, “Info1”);
    }
    });

    $.ajax({
    type: “GET”,
    url: “test2.csv”,
    dataType: “text”,
    success: function (data) {
    processCSV1(data, “3000”, “000”, “Info1”);
    }
    });

    function processCSV1(allText, containerID, titleText, axYTitle) {
    var allLinesArray = allText.split(“\n”);
    if (allLinesArray.length > 0) {
    var dataPoints1 = [];
    var dataPoints2 = [];
    for (var i = 0; i <= allLinesArray.length – 1; i++) {
    var rowData = allLinesArray[i].split(“;”);
    dataPoints1.push({
    label: rowData[0],
    y: parseFloat(rowData[1])
    });

    dataPoints2.push({
    label: rowData[0],
    y: parseFloat(rowData[1])
    });
    }

    var chart = new CanvasJS.Chart(containerID, {
    animationEnabled: true,
    zoomEnabled: true,
    title: {
    text: titleText,
    fontSize: 25
    },
    axisX: {
    title: “Graphe1”,

    },
    axisY: {
    title: axYTitle,
    },
    legend: {
    horizontalAlign: “center”,
    verticalAlign: “top”,
    fontSize: 15
    },
    data: [{
    type: “line”,
    markerType: “circle”,
    dataPoints: dataPoints1
    },
    {
    type: “line”,
    markerType: “circle”,
    dataPoints: dataPoints2

    }]

    });
    chart.render();
    }
    }

    it shows me that a curve, how i can do?

    #23252

    @lola123,

    Please take a look at this JSFiddle on rendering a multi-series chart using multiple external CSV files.

    __
    Priyanka M S
    Team CanvasJS

    #28081

    Hello

    I have this:

    File1
    a,10
    b,12
    c,29
    d,34
    e,28

    File2
    c,35
    d,27
    e,21

    When I load the files into datapoints, the chart line for file2 is drawed at “a,b,c” level form File1, and I expected this to start only at “c,d,e” level.

    How to get this working properly?

    Thanks

    #28105

    @santossg,

    dataPoints are aligned based on the x values and not the label. Assigning x values to the corresponding label and mapping it according to the label values should work fine in your case.

    ___________
    Indranil Deo
    Team CanvasJS

    #28136

    Thanks Indranil, I had used the label instead of x. It works now.

    Very thanks.

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

You must be logged in to reply to this topic.