高图表代码中的条件

Conditions within highcharts code

本文关键字:条件 代码 高图表      更新时间:2023-09-26

>问题

我正在尝试在我的移动应用程序上使用Highcharts,该应用程序正在使用Phonegap进行开发。我通过 AJAX 从数据库中获取了数据。当我根据我在 highcharts 代码中获得的数据放置 If{}Else{} 条件时,它已经过测试并且基本上工作正常,它给了我一个错误。无论哪个 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
            }
        },

杰森问题

//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",data: []},{name: "Don",data: []}"

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

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

在 JSON 中,您不能使用条件,可以在 durign 预处理期间完成,在 json 中您可以使用 returend 值。

在这里,当您使用Highcharts创建图表时,它期望我们传递给它的选项很少,这些选项取决于图表的呈现方式,

在你设置条件的选项集之间,

而不是使用 if 否则你可以使用三元运算符

tickInterval: (graphdefault == 0) ? 24 * 3600 * 1000 * 7 : ((graphdefault == 1) ? 24 * 3600 * 1000 * 7 : null),

这将起作用,因为在访问 tickInterval 选项时会评估条件。

试试吧,希望这会有用