Delay

Delay - 图1

config setup actions

  1. var delayed;
  2. const config = {
  3. type: 'bar',
  4. data: data,
  5. options: {
  6. animation: {
  7. onComplete: () => {
  8. delayed = true;
  9. },
  10. delay: (context) => {
  11. let delay = 0;
  12. if (context.type === 'data' && context.mode === 'default' && !delayed) {
  13. delay = context.dataIndex * 300 + context.datasetIndex * 100;
  14. }
  15. return delay;
  16. },
  17. },
  18. scales: {
  19. x: {
  20. stacked: true,
  21. },
  22. y: {
  23. stacked: true
  24. }
  25. }
  26. }
  27. };
  1. const DATA_COUNT = 7;
  2. const NUMBER_CFG = {count: DATA_COUNT, min: -100, max: 100};
  3. const labels = Utils.months({count: 7});
  4. const data = {
  5. labels: labels,
  6. datasets: [
  7. {
  8. label: 'Dataset 1',
  9. data: Utils.numbers(NUMBER_CFG),
  10. backgroundColor: Utils.CHART_COLORS.red,
  11. },
  12. {
  13. label: 'Dataset 2',
  14. data: Utils.numbers(NUMBER_CFG),
  15. backgroundColor: Utils.CHART_COLORS.blue,
  16. },
  17. {
  18. label: 'Dataset 3',
  19. data: Utils.numbers(NUMBER_CFG),
  20. backgroundColor: Utils.CHART_COLORS.green,
  21. },
  22. ]
  23. };
  1. const actions = [
  2. {
  3. name: 'Randomize',
  4. handler(chart) {
  5. chart.data.datasets.forEach(dataset => {
  6. dataset.data = Utils.numbers({count: chart.data.labels.length, min: -100, max: 100});
  7. });
  8. chart.update();
  9. }
  10. },
  11. ];