Search code examples
angulartypescriptnativescriptnativescript-angular

Does anyone have a sample for RadPieChart for nativescript + angular?


I'm creating a cross-platfrom app that has to display a PieChart on my home tab. Where can I find a complete example?

I try to follow this tutorial changing it based on the version I'm using but doesn't work and in my opinion the first part doesn't match the second part.

This is a part of home.component.html

<RadPieChart id="pieChartGiacenze" allowAnimation="true">
            <RadPieChart.series>
              <DonutSeries
                  selectionMode="DataPoint"
                  expandRadius="0.4"
                  outerRadiusFactor="0.7"
                  innerRadiusFactor="0.4"
                  valueProperty="Amount"
                  legendLabel="Brand"
                  [items]="pieSource">
              </DonutSeries>
            </RadPieChart.series>
            <RadPieChart.legend>
              <RadLegendView position="Right" offsetOrigin="TopRight" width="110" enableSelection="true"></RadLegendView>
            </RadPieChart.legend>
          </RadPieChart>

and this is a part of home.component.ts

public pieSource;

//.....somecode.....

this.pieSource = new ObservableArray();
      this.pieSource.push({Brand:"ciao", Amount:50});
      this.pieSource.push({Brand:"mondo", Amount:80});

I can't see the chart in my home. Where am I wrong?


Solution

  • Here is the sample, in .html file

    <GridLayout height="500" rows="auto,*">
                    <Label text="Test Pie Chart" row="0"></Label>
                    <RadPieChart allowAnimation="true" row="1">
                        <PieSeries tkPieSeries selectionMode="DataPoint"
                            expandRadius="0.4" outerRadiusFactor="0.7" [items]="pieSource"
                            valueProperty="Amount" legendLabel="Brand"></PieSeries>
                        <RadLegendView tkPieLegend position="Right" offsetOrigin="Bottom"
                            width="100" enableSelection="true" offsetOrigin="TopRight"></RadLegendView>
                    </RadPieChart>
                </GridLayout>
    

    and in your .ts file

    pieSource: { Brand: string, Amount: number }[] = [
            { Brand: "Audi", Amount: 10 },
            { Brand: "Mercedes", Amount: 76 },
            { Brand: "Fiat", Amount: 60 },
            { Brand: "BMW", Amount: 24 },
            { Brand: "Crysler", Amount: 40 }
        ];
    

    Here is the playground for you.