如果条件不适用于 ChartJS [英] If condition not working for ChartJS

查看:22
本文介绍了如果条件不适用于 ChartJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用chartjs仪表板页面.我在底部标签颜色问题上遇到了一些问题.我得到了解决方案,但如果条件对我不起作用.请任何人帮助我.

I am trying to chartjs dashboard page.I am got some issues in bottom label color problem.I get the solution but if condtion not working to me.Please any one help me.

我的代码.....

generateLabels: function(chart) {
   var get_label = _.pluck(chart.data.datasets, 'label');
   var join_label = _.flatten(get_label);
   var get_color = _.pluck(chart.data.datasets, 'backgroundColor');
   var join_color = _.flatten(get_color);
   var get_data = {
        label: join_label,
        backgroundColor: join_color
  }
  for (k = 0; k < get_data.label.length; k++) {
     return get_data.label.map(function(label, i) {
        if(label != 'undefined'){
           return {
               text: label,
               fillStyle: get_data.backgroundColor[i]
           };
        }
      });
   }

}

if(label != 'undefined') 这个条件不起作用...

if(label != 'undefined') this condition not working...

推荐答案

我认为您的问题是 undefined 是一个关键字,因此您不必将它放在引号之间.试试 if (label != null && label != undefined) { ... }

I think your problem is that undefined is a keyword so you don't have to put it between quotes. Try with if (label != null && label != undefined) { ... }

这篇关于如果条件不适用于 ChartJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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