很高兴的图表堆叠条形图数据不能通过javascript工作 [英] highchart stacked bar plotting data doesn't work by javascript

查看:114
本文介绍了很高兴的图表堆叠条形图数据不能通过javascript工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么会这样,我在一个bar highchart中绘制一个数据时遇到麻烦。我正在使用这个 chart.series [i] .addPoint(data [i] ['total_check']); 但是当我提醒 alert [i] ['total_check']); 有价值,但是当我去batchart,它不会出现。我想知道我的代码是否出错? 。
这是我的代码,我绘制从barchart的点:

  function getbarseries(month){
$ .ajax({
url:siteurl +patients_report / bardataclinic /+ month,
type:POST,
dataType:JSON,
success:function ){
for(var i in data){
chart.series [i] .addPoint(data [i] ['total_check']);
// alert(data [i] ['total_check']);
}
}
});
}

我通过执行递归方式绘制图表,所以主要部分我的代码是这样的:

  function getbarxAxis(){
$ .ajax({
url:siteurl + patient_report / bardata_date,
type:POST,
dataType:JSON,
success:function(data){
var categories = new Array();
for(var i in data){
categories.push(data [i] [datemonths]);
}
loadChart(categories);
getallclinics );
var arrayLength = categories.length;
for(var loop = 0; loop< arrayLength; loop ++){
getbarseries(categories [loop]);
}

}
});
}

我正在制作一个动态酒吧highchart,这就是为什么第一,我得到类别几个月),查询我使用 loadChart(categories); 的功能后,我绘制了类别,

  function loadChart(categories){
chart = Highcharts.chart('container',{
chart:{
type:'bar'
} ,
title:{
text:''
},
xAxis:{
类别:类别
},
yAxis:{
分:0,
标题:{
文本:'每诊所详细病人'
}
},
legend:{
reverse: true
},
plotOptions:{
系列:{
stacking:'normal'
}
},
plotOptions:{
系列:{
stacking:'normal'
}
}
});
}

之后我绘制了类别,其次是系列数据名称,其中我还在我的数据库中查询一个新的函数,并绘制所有的数据系列名称,命名为: getallclinics();
getallclinics函数的全代码是这是:

  function getallclinics(){
$ .ajax({
url:siteurl +patients_report /
类型:POST,
async:false,
dataType:JSON,
success:function(data){
for(var i在数据中){
chart.addSeries({
name:data [i] ['clinic_name']
});
}
}
} );
}

在得到诊所后,最后一部分是我有麻烦,在那里我想绘制所宣布的系列名称的数据,所以上面的代码是 getbarseries 是我遇到麻烦的地方,我在那里绘制 chart.series [i] .addPoint(data [i] ['total_check']);



我的getbarseries的完整代码: / p>

  function getbarseries(month){
$ .ajax({
url:siteurl +patients_report / bardataclinic / + month,
type:POST,
dataType:JSON,
success:function(data){
for(var i in data){
chart.series [i] .addPoint(data [i] ['total_check']);
// alert(data [i] ['total_check']);
}
}
});
}

我在那里做了每个月从函数getbarseries(月),我得到我的几个月的全面检查:
这是我的控制台的结果,因为我只有两个返回的月份从我的类别,然后我有两个递归循环 getbarseries 功能



第一个递归循环: [{clinic_name:Clinic 1,total_check:0},{clinic_name 诊所2,total_check:1},{clinic_name:Clinic 3,total_check:0},{clinic_name:Clinic 4,total_check 0}]



第二递归循环: [{clinic_name:Clinic 1,total_check :2},{clinic_name:Clinic 2,total_check:0},{clinic_name:Clinic 3,total_check:0},{clinic_name诊所4,total_check:0}]

解决方案

字符串,您需要将其解析为数字。



您可以使用以下内容:将参数转换为数字

  function getbarseries(month){
$ .ajax({
url:siteurl +patients_report / bardataclinic /+ month,
type:POST,
dataType:JSON,
success: function(data){
for(var i in data){
chart.series [i] .addPoint(Number(data [i] ['total_check']));
}
}
});
}


why is this, i am having a trouble in plotting a data in bar highchart. I am using this chart.series[i].addPoint(data[i]['total_check']); but when i alert alert(data[i]['total_check']); there are values, but when i go plot it in barchart, it doesn't appear. I am wondering if my code is in a wrong way ? . Here is my code where i plot the points from barchart :

function getbarseries(month) {
    $.ajax({
      url: siteurl+"patients_report/bardataclinic/"+month,
      type: "POST",
      dataType: "JSON",
        success: function(data) {
           for(var i in data) {
               chart.series[i].addPoint(data[i]['total_check']);
               //alert(data[i]['total_check']);
           }
        }
    });
}

i am plotting a chart by doing a recursive way , so the main part of my code is this :

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

   }
 });
}

i am making a dynamic bar highchart thats why first, i am getting categories (months) with query to the function that i use loadChart(categories); after i plotted the categories,

function loadChart(categories) {
   chart = Highcharts.chart('container', {
    chart: {
        type: 'bar'
    },
    title: {
        text: ''
    },
    xAxis: {
        categories: categories
    },
    yAxis: {
        min: 0,
        title: {
            text: 'Detailed patient per clinic'
        }
    },
    legend: {
        reversed: true
    },
    plotOptions: {
        series: {
            stacking: 'normal'
        }
    },
    plotOptions: {
            series: {
                stacking: 'normal'
            }
    }
});
}

after i plotted the categories, next within it is the series data name, where i also make a new function to query in my database and plot all the data series names, the function named : getallclinics(); the fullcode of getallclinics function is this:

function getallclinics() {
   $.ajax ({
          url: siteurl+"patients_report/seriesclinics",
          type: "POST",
          async: false,
          dataType: "JSON",
          success: function(data) {
            for(var i in data) {
              chart.addSeries({
                  name: data[i]['clinic_name']
              });
            }
          }
   });
}

after getting the clinics, the last part is what i've got trouble, where i want to plot the data from the series name declared, so the code above which is the getbarseries is what i am having trouble, where i plot there chart.series[i].addPoint(data[i]['total_check']);

Full code of my getbarseries:

function getbarseries(month) {
    $.ajax({
      url: siteurl+"patients_report/bardataclinic/"+month,
      type: "POST",
      dataType: "JSON",
        success: function(data) {
           for(var i in data) {
               chart.series[i].addPoint(data[i]['total_check']);
               //alert(data[i]['total_check']);
           }
        }
    });
}

what i did there was every month from the function getbarseries(month), i got my months with a total checkup : here is the result from my console since i have only two returned months from my categories , then i have two recursive loops for getbarseries function

first recursive loop: [{"clinic_name":"Clinic 1","total_check":"0"},{"clinic_name":"Clinic 2","total_check":"1"},{"clinic_name":"Clinic 3","total_check":"0"},{"clinic_name":"Clinic 4","total_check":"0"}]

second recursive loop: [{"clinic_name":"Clinic 1","total_check":"2"},{"clinic_name":"Clinic 2","total_check":"0"},{"clinic_name":"Clinic 3","total_check":"0"},{"clinic_name":"Clinic 4","total_check":"0"}]

解决方案

you data seem to be strings, you need to parse them to be numbers.

You can use this: Convert argument to number

function getbarseries(month) {
    $.ajax({
      url: siteurl+"patients_report/bardataclinic/"+month,
      type: "POST",
      dataType: "JSON",
        success: function(data) {
           for(var i in data) {
               chart.series[i].addPoint(Number(data[i]['total_check']));
           }
        }
    });
}

这篇关于很高兴的图表堆叠条形图数据不能通过javascript工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆