load data in highcharts from 2 different csv files

后端 未结 1 1643
误落风尘
误落风尘 2021-01-14 16:45

I am trying to find out if I can get a graph using 2 sources (one for the categories, another for the actual data plotted.

I find myself often in need to use the sam

相关标签:
1条回答
  • 2021-01-14 17:25

    Here you can find example how to load three files as series: http://www.highcharts.com/stock/demo/compare

    So the only difference would be that you are using just one series, and second file will be used for categories data.

    In above solution added is some global counter, to render chart after all files are received.

    Second solution will be to call second AJAX inside callback for a first one, snippet:

    $.getJSON(url1, function(data) {
        $.getJSON(url2, function(data2) {
            // create chart here
        });
    });
    

    Edit:

    If you have two CSV files, this is what you need to change:

    $.get(url1, function(data1) {
        $.get(url2, function(data2) {
            // parse data1
            var parsedData1 = ...
            // parse data2
            var parsedData2 = ...
    
            $("#container").highcharts({
               series: [{
                   data: parsedData1
               }, {
                   data: parsedData2
               }]
            });
        });
    });
    
    0 讨论(0)
提交回复
热议问题