0

Hi I want to push For Loop Value in Array

My View

  <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
 <style>    
body {
    font-family: Roboto, sans-serif;
}
#chart {
    max-width: 650px;
    margin: 35px auto;
}
 </style>
  <div id="chart">
  </div>
  <script src="~/Scripts/jquery-1.8.2.min.js"></script>
 <script type="text/javascript">


$(document).ready(function () {
    debugger;
    var cval = "In-Progress";
    $.ajax({
        type: "Post",
        url: '@Url.Action("GetProjectList", "Dashboard")',
        datatype: "Json",
        data: { status: cval },
        success: function (data) {
            debugger;
            console.log(data);
            var catagorydata = new Array();
            var Estimation = new Array();                           
            for (var i = 0; i < data.data.length; i++) {
                catagorydata.push[data.data[i].ProjectID];
                Estimation.push[data.data[i].EstimatedValue];
            }               
            var options = {
                chart: {
                    type: 'line'
                },
                series: [{
                    name: 'sales',

                    data: Estimation
                }],
                xaxis: {
                    categories: catagorydata
                }
            }
            var chart = new ApexCharts(document.querySelector("#chart"), options);
            chart.render();
        }
        })
});
</script>

Here in Ajax Success Function I am getting 5 values in data .Then I used For loop and push the value in array but the value is not storing in array

                catagorydata.push[data.data[i].ProjectID];
                Estimation.push[data.data[i].EstimatedValue];

In categorydata and Estimation are arrays and the for loop values is not storing in these ararys.Kindly any one help me to resolve this issue .

2
  • 1
    push is a function, and is called like all other functions ... with () not [] Commented May 15, 2020 at 4:39
  • Yes @JaromandaX i missed to check this.Thanks. Commented May 15, 2020 at 4:54

1 Answer 1

1

There seems to be a syntax issue. push is a method and hence should use brackets rather than square brackets.

catagorydata.push(data.data[i].ProjectID);
Estimation.push(data.data[i].EstimatedValue);
Sign up to request clarification or add additional context in comments.

1 Comment

Yes i forgot to check that .Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.