|
| 1 | +import { Color } from '@nativescript/core'; |
| 2 | +import { BarChart } from '@nativescript-community/ui-chart/charts'; |
| 3 | +import { BarData } from '@nativescript-community/ui-chart/data/BarData'; |
| 4 | +import { BarDataSet } from '@nativescript-community/ui-chart/data/BarDataSet'; |
| 5 | + |
| 6 | +function getRandomInt(min, max) { |
| 7 | + return Math.floor(Math.random() * (max - min + 1)) + min; |
| 8 | +} |
| 9 | + |
| 10 | +function getRandomColor() { |
| 11 | + const r = getRandomInt(0, 255); |
| 12 | + const g = getRandomInt(0, 255); |
| 13 | + const b = getRandomInt(0, 255); |
| 14 | + return new Color(255, r, g, b); |
| 15 | +} |
| 16 | + |
| 17 | +export function onChartLoaded(args) { |
| 18 | + const chart = args.object as BarChart; |
| 19 | + |
| 20 | + chart.drawFameRate = true; |
| 21 | + // chart.setLogEnabled(true); |
| 22 | + chart.setScaleEnabled(true); |
| 23 | + chart.setDragEnabled(true); |
| 24 | + chart.getAxisRight().setEnabled(false); |
| 25 | + chart.setHighlightPerTapEnabled(true); |
| 26 | + // chart.setHardwareAccelerationEnabled(true); |
| 27 | + |
| 28 | + const data = new Array(5).fill(0).map(function (v, i) { |
| 29 | + return { index: i, value: Math.random() * 1 }; |
| 30 | + }); |
| 31 | + |
| 32 | + const sets = []; |
| 33 | + const set = new BarDataSet(data, 'Dataset Label', 'index', 'value'); |
| 34 | + set.setDrawIcons(true); |
| 35 | + set.setColor(getRandomColor()); |
| 36 | + set.setDrawValues(true); |
| 37 | + sets.push(set); |
| 38 | + |
| 39 | + // Create a data object with the data sets |
| 40 | + const bd = new BarData(sets); |
| 41 | + |
| 42 | + // Set data |
| 43 | + chart.setData(bd); |
| 44 | +} |
| 45 | + |
| 46 | +export function redraw(args) { |
| 47 | + const page = args.object.page; |
| 48 | + |
| 49 | + const chart = page.getViewById('chart'); |
| 50 | + if (chart) { |
| 51 | + chart.invalidate(); |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +export function onNavigationButtonTap(args) { |
| 56 | + args.object.page.frame.goBack(); |
| 57 | +} |
0 commit comments