Kavrat
Kavrat

Reputation: 87

Uncaught TypeError: t.ticks.map is not a function, Chart.JS

I have this js code

    $.ajax({
    url: "/home/getmonthly/",
    type: "GET",
    success: onSuccess,
    error: onErrorCall

    });
    function onSuccess(result) {
        var ctx = $("#BarChart")[0].getContext('2d');
        var myChart = new Chart(ctx, {
        type: 'bar',
        data: {
            labels: "something",
            datasets: [{
                label: 'revenues',
                data: result.Revenues,
                backgroundColor: 'rgba(75, 192, 192, 0.2)',
                borderColor: 'rgba(75, 192, 192, 1)',
                borderWidth: 1
            },
            {
                label: 'expenses',
                data: result.Expenses,
                backgroundColor: 'rgba(54, 162, 235, 0.2)',
                borderColor: 'rgba(54, 162, 235, 1)',
                borderWidth: 1
            }]

        },
        options: {
            barValueSpacing: 20,
            scales: {
                yAxes: [{
                    ticks: {
                        min: 0
                    }
                }]
            }
        }
    });
}

   function onErrorCall(response) {
       alert('error');
   }

And controller with ViewModel (they works fine)

public JsonResult GetMonthly()
    {
        var sixMonth = DateTime.Now.AddMonths(-6);
        MonthlyValuesViewModel mv = new MonthlyValuesViewModel();

        mv.Expenses = (from x in db.Activities
                       where x.Operations.TypeOperations.TypeId == 2 &
                       x.Date > sixMonth
                       group x by x.Date.Month into monthgroup
                       select monthgroup.Sum(x => x.Amount)).ToArray();

        mv.Revenues = (from x in db.Activities
                      where x.Operations.TypeOperations.TypeId == 1 &
                      x.Date > sixMonth
                      group x by x.Date.Month into monthgroup
                      select monthgroup.Sum(x => x.Amount)).ToArray();



        return Json(mv, JsonRequestBehavior.AllowGet);
    }


public class MonthlyValuesViewModel
{
    public double [] Revenues { get; set; }
    public double [] Expenses { get; set; }
}

After compilling I got this error:

Uncaught TypeError: t.ticks.map is not a function at n.convertTicksToLabels (Chart.min.js:12) at n.update (Chart.min.js:12) at r (Chart.min.js:12) at Object.o.each (Chart.min.js:12) at Object.update (Chart.min.js:12) at t.updateLayout (Chart.min.js:11) at t.update (Chart.min.js:11) at t.construct (Chart.min.js:11) at new t (Chart.min.js:12) at Object.onSuccess [as success] (sb-admin-charts.js:10)

Please, tell me what should I do to fix this problem?

Upvotes: 1

Views: 2220

Answers (1)

Kavrat
Kavrat

Reputation: 87

Fixed! Mistake was in that string:

labels: "something",

I had to assign an array of string and not one string

Upvotes: 1

Related Questions