UNPKG

@nativescript-community/ui-chart

Version:

A powerful chart / graph plugin, supporting line, bar, pie, radar, bubble, and candlestick charts as well as scaling, panning and animations.

55 lines (54 loc) 1.79 kB
import { ChartData } from './ChartData'; /** * A PieData object can only represent one DataSet. Unlike all other charts, the * legend labels of the PieChart are created from the x-values array, and not * from the DataSet labels. Each PieData object can only represent one * PieDataSet (multiple PieDataSets inside a single PieChart are not possible). * */ export class PieData extends ChartData { /** * Sets the PieDataSet this data object should represent. * * @param dataSet */ setDataSet(dataSet) { this.mDataSets.splice(0); this.mDataSets.push(dataSet); this.notifyDataChanged(); } /** * Returns the DataSet this PieData object represents. A PieData object can * only contain one DataSet. */ getDataSet() { return this.mDataSets[0]; } /** * The PieData object can only have one DataSet. Use getDataSet() method instead. * * @param index * @return */ getDataSetByIndex(index) { return index === 0 ? this.getDataSet() : null; } getDataSetByLabel(label, ignoreCase) { return ignoreCase ? (label?.toLowerCase() === this.mDataSets[0].label?.toLowerCase() ? this.mDataSets[0] : null) : label === this.mDataSets[0].label ? this.mDataSets[0] : null; } getEntryForHighlight(highlight) { return this.getDataSet().getEntryForIndex(highlight.x); } /** * Returns the sum of all values in this PieData object. */ getYValueSum() { const yKey = this.getDataSet().yProperty; let sum = 0; for (let i = 0; i < this.getDataSet().entryCount; i++) { sum += this.getDataSet().getEntryForIndex(i)[yKey]; } return sum; } } //# sourceMappingURL=PieData.js.map