How to bind chart data in constructor using httpmodule


#1

Hi,

I have static data for pie chart data source in application and it’s working file. But when I bind that data using http call, chart is showing blank. Please suggest. Following is the code.

import { Observable } from ‘tns-core-modules/data/observable/observable’;
//import { Observable } from ‘data/observable’;
export class HomeViewModel extends Observable {

constructor() {
    super();
    this.set("lat", this.monthlyPieSource);
    this.set("selectedChart", "monthly");
}

lat = "";
selectedChart = "";

ProductSource: { PRODUCTCODE: string, PRODUCTSALESCOUNT: number }[] = [
    { PRODUCTCODE: "88L", PRODUCTSALESCOUNT: 15 },
    { PRODUCTCODE: "80R", PRODUCTSALESCOUNT: 13 },
    { PRODUCTCODE: "35L", PRODUCTSALESCOUNT: 9 },
    { PRODUCTCODE: "70R", PRODUCTSALESCOUNT: 8 },
    { PRODUCTCODE: "12SV100L", PRODUCTSALESCOUNT: 8 }
];

monthlyPieSource: { BRANDDESC: string, BRANDSALESCOUNT: number }[] = [
    {
        BRANDDESC: "HUPS",
        BRANDSALESCOUNT: 1
    },
    {
        BRANDDESC: "INSTAGEN",
        BRANDSALESCOUNT: 1
    }
];

quartlyPieSource: { BRANDDESC: string, BRANDSALESCOUNT: number }[] = [
    {
        BRANDDESC: "HUPS",
        BRANDSALESCOUNT: 1
    },
    {
        BRANDDESC: "INSTAGEN",
        BRANDSALESCOUNT: 1
    },
    {
        BRANDDESC: "AUTORIDER",
        BRANDSALESCOUNT: 4
    }
];

yearlyPieSource: { BRANDDESC: string, BRANDSALESCOUNT: number }[] = [
    {
        BRANDDESC: "HUPS",
        BRANDSALESCOUNT: 1
    },
    {
        BRANDDESC: "INSTAGEN",
        BRANDSALESCOUNT: 1
    }
];

SalesTrendSource: { Month: string, Quantity: number }[] = [
    {
        Month: "June",
        Quantity: 57
    },
    {
        Month: "July",
        Quantity: 55
    }
];

getLocation(args): void {
    console.log(args.object.path);
    if (args.object.path == "monthly") {
        this.set("lat", this.monthlyPieSource);
        this.set("selectedChart", "monthly");
    }
    if (args.object.path == "quartly") {
        this.set("lat", this.quartlyPieSource);
        this.set("selectedChart", "quartly");
    }
    if (args.object.path == "yearly") {
        this.set("lat", this.yearlyPieSource);
        this.set("selectedChart", "yearly");
    }
}

}


#2

Would you mind building a Playground example which will be easy to debug?