chart.js 990 B

12345678910111213141516171819202122232425262728293031323334353637
  1. export default {
  2. template: "<div></div>",
  3. mounted() {
  4. setTimeout(() => {
  5. const imports = this.extras.map((extra) => import(window.path_prefix + extra));
  6. Promise.allSettled(imports).then(() => {
  7. this.chart = Highcharts[this.type](this.$el, this.options);
  8. this.chart.reflow();
  9. });
  10. }, 0); // NOTE: wait for window.path_prefix to be set in app.mounted()
  11. },
  12. beforeDestroy() {
  13. this.destroyChart();
  14. },
  15. beforeUnmount() {
  16. this.destroyChart();
  17. },
  18. methods: {
  19. update_chart() {
  20. if (this.chart) {
  21. while (this.chart.series.length > this.options.series.length) this.chart.series[0].remove();
  22. while (this.chart.series.length < this.options.series.length) this.chart.addSeries({}, false);
  23. this.chart.update(this.options);
  24. }
  25. },
  26. destroyChart () {
  27. if (this.chart) {
  28. this.chart.destroy()
  29. }
  30. }
  31. },
  32. props: {
  33. type: String,
  34. options: Object,
  35. extras: Array,
  36. },
  37. };