mardi 22 novembre 2016

The use of string argument in an "IF" statement

So, I was trying to make 2 javascript methods. The first method is to do the graphMaking AND the other to send the correct parameters to the first method to make the graph according to the sent parameters.The problem is, i need to loop the parameters sent with "arguments[i]" in order to form a string of:

data[i].Names == "A" || data[i].Names == "B"

and here's what i came up with:

  var numIndex = [];
  var cityString = "";
                for (var j = 1; j < arguments.length; j++)
                {
                    cityString = cityString + "||" + " data[i].Names==\"" + arguments[j] + "\"";
                    alert(arguments[j]);
                }
                cityString = "data[i].Names==\"" + arguments[0] + "\"";
    for (var i = 0; i < data.length; i++) {
      if (cityString)
      {
        numIndex.push(i);
      }
    }

what should my if (cityString) be replaced with in rder for this to work? Thanks in advance :)

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

[EDIT] Okay heres the real deal why its C# is because i was doing the code in asp.net which was dumb of me and heres the real code:

function makeGraph() {
        var chrt = document.getElementById("myCanvas");
        $.ajax({
            url: '../api/values',
            type: 'GET',
            datatype: 'json',
            success: function (data) {
                var totalLabel = [];
                var totalValue = [];
                var totalLabel2 = [];
                var totalValue2 = [];
                var cityValue = [];
                var cityName = [];
                var numIndex = [];
                var cityString = "";
                for (var j = 1; j < arguments.length; j++)
                {
                    cityString = cityString + "||" + " data[i].Names==\"" + arguments[j] + "\"";
                    alert(arguments[j]);
                }
                cityString = "data[i].Names==\"" + arguments[0] + "\"";
                for (var i = 0; i < data.length; i++) {
                    totalLabel.push(data[i].Names);
                    totalValue.push(data[i].ValuesDouble);
                    totalLabel2.push(data[i].Names2);
                    totalValue2.push(data[i].ValuesDouble2);
                    if (cityString) {
                        numIndex.push(i);
                    }

                }
                for (var k = 0; k < numIndex.length; k++) {
                    cityValue.push(data[numIndex[k]].ValuesDouble);
                    cityName.push(data[numIndex[k]].Names);
                }

                $(function () {
                    Highcharts.chart('container', {
                        chart: {
                            type: 'column',
                            backgroundColor: 'black'
                        },
                        title: {
                            text: ''
                        },
                        xAxis: {
                            categories: cityName,

                        },
                        yAxis: {
                            min: 0,
                            tickInterval: 100000,
                            title: {
                                text: ''
                            }
                        },
                        legend: {
                            verticalAlign: 'top',
                            reversed: false,
                            backgroundColor: 'lightgrey'
                        },
                        plotOptions: {
                            series: {
                                stacking: 'normal'
                            }
                        },
                        series: [

                        {
                            name: 'Joe',
                            data: cityValue,
                            color: 'green'

                        },
                         {
                             name: 'Joe',
                             data: cityValue,
                             color: 'yellow'
                         },
                        {
                            name: 'Jane',
                            data: cityValue,
                            color: 'blue'
                        }]
                    });
                });

            }
        })

    }

Aucun commentaire:

Enregistrer un commentaire