HistogramHorizontal.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <!-- 水平方向的柱状图 -->
  2. <template>
  3. <div :id="chartId"></div>
  4. </template>
  5. <script>
  6. import { Chart } from "@antv/g2";
  7. import superHorizontal from "./SuperComponent";
  8. export default {
  9. name: "chart",
  10. data() {
  11. return {
  12. ...superHorizontal.rootComponent.data(),
  13. chart: null
  14. };
  15. },
  16. props: superHorizontal.rootComponent.props,
  17. mounted() {
  18. this.drawChart();
  19. },
  20. watch: {
  21. chartData: function(val) {
  22. this.chart.changeData(val); // 动态更新数据
  23. }
  24. },
  25. methods: {
  26. drawChart: function() {
  27. console.log("XXXXSSSS", this.chartId);
  28. // Step 1: 创建 Chart 对象
  29. this.chart = new Chart({
  30. container: this.chartId, // 指定图表容器 ID
  31. autoFit: true,
  32. height: 400
  33. });
  34. this.chart.data(this.chartData);
  35. this.chart.scale("sold", { nice: true });
  36. this.chart.coordinate().transpose();
  37. this.chart.tooltip({
  38. showMarkers: false
  39. });
  40. this.chart.interaction("active-region");
  41. this.chart.interval().position("genre*sold");
  42. this.chart.render();
  43. }
  44. }
  45. };
  46. </script>
  47. <style scoped>
  48. </style>