Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
424 views
in Technique[技术] by (71.8m points)

javascript - Highchart dynamic data adding with addSeries array

How can I manage this or making this dynamic? I am using a highchart bar, and I don't know how to make this part of the code to be a dynamic :

series: [{
         name: 'Clinic 1',

         data: [3, 3, 4, 7, 3]
     }, {
         name: 'Clinic 2',
         data: [2, 2, 3, 2, 4]
     }, {
         name: 'Clinic 3',
         data: [3, 4, 4, 2, 1]
     }] 

here in my situation, i am trying to make it dynamic, i have no idea how to make the data:[] to be a dynamic, something like my problem is the length of the array data[] and also, another problem, i've also know a little bit about addSeries function, where its syntax is :

chart.addSeries({
    name: example
    data: example
})

can i separate the name and the data within it? because if i will include the name in populating the loop, it would duplicate, also i am thinking that i need a multiple loop for populating the data part of the addseries function Here is my code where i have all the data, but i don't know how to plot it with addSeries to be a dynamic.

function getbarxAxis() {
  getallclinics();
  var arrayLength = myclinicsID.length;
 $.ajax({
   url: siteurl+"patients_report/bardata_date",
   type: "POST",
   dataType: "JSON",
   success: function(data) {
     for (var i in myclinicsID) {
       categories.push(data[i]["datemonths"]);

          for(var innerLoop = 0; innerLoop < arrayLength; innerLoop++) {        
            getbarSeriesData(myclinicsID[innerLoop],data[i]['datemonths']);

         }
     }
    loadChart(categories);
   }
 });
}
    function getbarSeriesData(clinicID,month) {
    $.ajax({
        url: siteurl+"patients_report/get_checkup/"+month+"/"+clinicID,
        type: "POST",
        dataType: "JSON",
        success: function(data) {
          alert (data[0]['total_check']);
        }
    });
}

Here in my code, I already plotted the xAxis, where it consist of months: then every xAxis, I queried it to get the data, every months, and now I am struggling how to plot the data, where I need to separate the addSeries name and data because I will go with the first loop for the name, and the second loop, there I will put the data something like this:

for (var i in myclinicsID) {
chart.addSeries {
name: myclinicsNAME[i]
}

for(var innerLoop = 0; innerLoop < arrayLength; innerLoop++) {
  getbarSeriesData(myclinicsID[innerLoop],data[i]['datemonths']); // inside of this is the addseries data
}
}

CONSOLE FOR

POST 
XHR 
http://localhost/clinic/patients_report/get_checkup/March/1 [HTTP/1.1 200 OK 83ms]
POST 
XHR 
http://localhost/clinic/patients_report/get_checkup/March/2 [HTTP/1.1 200 OK 76ms]
POST 
XHR 
http://localhost/clinic/patients_report/get_checkup/March/3 [HTTP/1.1 200 OK 165ms]
POST 
XHR 
http://localhost/clinic/patients_report/get_checkup/March/4 [HTTP/1.1 200 OK 70ms]
POST 
XHR 
http://localhost/clinic/patients_report/get_checkup/April/1 [HTTP/1.1 200 OK 87ms]
POST 
XHR 
http://localhost/clinic/patients_report/get_checkup/April/2 [HTTP/1.1 200 OK 142ms]
POST 
XHR 
http://localhost/clinic/patients_report/get_checkup/April/3 [HTTP/1.1 200 OK 180ms]
POST 
XHR 
http://localhost/clinic/patients_report/get_checkup/April/4 [HTTP/1.1 200 OK 146ms]

each console has this response:

0:Object
  clinic_name: "Clinic 1"
  total_check: "0"
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...