HistogramHorizontal.vue 926 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 superHorizontal.rootComponent.data();
  12. },
  13. props: superHorizontal.rootComponent.props,
  14. mounted() {
  15. this.drawChart();
  16. },
  17. methods: {
  18. drawChart: function() {
  19. console.log("XXXXSSSS", this.chartId);
  20. // Step 1: 创建 Chart 对象
  21. const chart = new Chart({
  22. container: this.chartId, // 指定图表容器 ID
  23. autoFit: true,
  24. height: 400,
  25. padding: [40, 40]
  26. });
  27. // Step 2: 载入数据源
  28. chart.data(this.chartData);
  29. // Step 3: 创建图形语法,绘制柱状图
  30. chart.interval().position("genre*sold");
  31. // Step 4: 渲染图表
  32. chart.render();
  33. }
  34. }
  35. };
  36. </script>
  37. <style scoped>
  38. </style>