TrendChart.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template>
  2. <div>
  3. <div :id="id" :options="options"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import HighCharts from 'highcharts';
  8. export default {
  9. // 验证类型
  10. props: {
  11. id: {
  12. type: String
  13. },
  14. options: {
  15. type: Object
  16. }
  17. },
  18. data() {
  19. return {
  20. title: "积分趋势图",
  21. chart: null
  22. }
  23. },
  24. mounted() {
  25. this.chart = HighCharts.chart(this.id, this.options)
  26. },
  27. methods: {
  28. updateData: function (data) {
  29. if (!data) {
  30. return
  31. }
  32. while (this.chart.series.length > 0) {
  33. this.chart.series[0].remove()
  34. }
  35. if (data.filter_text) {
  36. let filterText = data.filter_text
  37. let titleSuffix = "( " + filterText.time_range + ")"
  38. if (filterText.employee) {
  39. titleSuffix += "・" + filterText.employee
  40. }
  41. if (filterText.dept) {
  42. titleSuffix += "・" + filterText.dept
  43. }
  44. if (filterText.category) {
  45. titleSuffix += "・" + filterText.category
  46. }
  47. this.chart.setTitle({text: this.title + titleSuffix})
  48. }
  49. if (data.chart) {
  50. let chartData = data.chart
  51. this.chart.xAxis[0].setCategories(chartData.labels)
  52. this.chart.addSeries({
  53. name: "奖分",
  54. data: chartData.p_positive.map(Number)
  55. })
  56. this.chart.addSeries({
  57. name: "扣分",
  58. data: chartData.p_negative.map(Number)
  59. })
  60. }
  61. }
  62. }
  63. }
  64. </script>