javascript - highcharts 代码中的条件

标签 javascript highcharts

问题

我正在尝试在我的移动应用程序上使用 Highcharts,该应用程序是使用 Phonegap 开发的。我通过AJAX从数据库获取数据。经过测试,基本上工作正常,当我根据 highcharts 代码中获得的数据设置 If{}Else{} 条件时,它会给出错误。无论我在 $(function () { 之后放置哪个 If, ELSE 条件,它都会引发错误。代码附在下面。有什么方法可以正常放置条件吗?提前致谢

代码

    //Get values from local storage
    var teamactivitygameGraph = window.localStorage.getItem("teamactivitygameGraph");
    AGW = JSON.parse(teamactivitygameGraph);

    //Assign values to the variables

    var game_start_on = AGW.game_start_on;
    var data_string = AGW.data_string;
    var data_avail = AGW.data_avail;
    var subText = AGW.subText;
    var graphdefault = user.graphdefault;
    var noofsundays = AGW.noofsundays;
    var total_user = AGW.total_user;
    var data = AGW.data;
    var yellowLineData = AGW.yellowLineData;
    var game_type = AGW.game_type;
    var danger_point = AGW.danger_point;
    var graph_image = AGW.graph_image;

    //Graph..

    $(function () {
       //var graphdefault = graphdefault;
       //var noofsundays = noofsundays;

       if(data_avail == 'no') {
            var styles = "x: -60,y:100,style: {color: '#8eb3ef',fontWeight: 'bold',fontSize: '36px'}";
        }else{
            var styles = "x: -25,";
        }

       if(graphdefault == 1 || (noofsundays == 1 && graphdefault == 1)){
            var showLabels = 'showFirstLabel: false,showLastLabel: false,';
        }

       $('#team_container').highcharts({
        chart: {
            type: 'bar',
            renderTo: 'container',
            zoomType: 'xy',
            events: {
                load: function() {
                    this.renderer.image(graph_image)
                        .add();
                }
            },
            zIndex: 5
        },
        title: {
            text: 'Team Activity Game',
            x: -20 //center
        },
        subtitle: {
             text: subText,
            if(data_avail == 'no') {
                x: -60, //center
                y:100,
                style: {
                 color: '#8eb3ef',
                 fontWeight: 'bold',
                 fontSize: '36px'
                }
            }else{
                x: -25, //center
            }
         },
        xAxis: {
        showLabels
          title: {
               text: 'Week Ending'
              },
            type: 'datetime',
            maxZoom: 24 * 3600000, // Two days
            labels: {
                 rotation: -45,
                 align: 'right',
                 formatter: function() {
                   return Highcharts.dateFormat('%d/%m/%Y', this.value);
                 }
             },
            if(graphdefault == 0){
            tickInterval: 24 * 3600 * 1000 * 7,
            startOfWeek: 0
            }elseif(graphdefault == 1){
            tickInterval: 24 * 3600 * 1000
            }
        },

Json问题

//I am taking this data from my Local Storage

var teamactivitygameGraph = window.localStorage.getItem("teamactivitygameGraph");
AGW = JSON.parse(teamactivitygameGraph);
var data = AGW.data;

alert (data);

当我警告 var data 时,它会输出正确的响应,即 "{name: "Joe",data: [[Date.parse('10/20/2013 UTC'), 8.9905667952813 ]]},{name: "Mark “,数据:[]},{名称:“唐”,数据:[]}”

但是当我将相同的变量放入 Highchart 代码(如下)时,它不会显示任何内容。

series: [
              data
             ,{
            name: 'yellowline',
            visible: false,
            showInLegend: false,
            data: yellowLineData
             }

        ]
   });

最佳答案

在 JSON 中您不能使用条件,它可以在预处理期间完成,并且在 json 中您可以使用返回值。

关于javascript - highcharts 代码中的条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19371918/

相关文章:

javascript - lodash:根据日期聚合和减少对象数组

javascript - 在 cordova inappbrowser 中添加按钮以隐藏它编辑 : and add image via Javascript to inappbrowser

php - Flickr API : Get list of all images with specific sizes

javascript - Nexus 7 (4.2.1) 上的 Highcharts 容器选择问题

javascript - 仅在悬停时通过 x 和 y 绘图线将文本添加到生成的象限区域,highcharts

css - 如何在堆积条形图上的轴标签之间创建更多间隙?

javascript - 调整大小、CSS 解决方案或仅使用 Javascript 时绝对 div 重叠兄弟?

javascript - 将数组中的数据连接到对象以通过中间人转换其值

javascript - 需要在变量饼 Highcharts 上放置边框吗?

typescript - 安装 highcharts 后 "Highcarts is not defined error"