HistogramHorizontals.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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,
  23. autoFit: true,
  24. height: 500
  25. });
  26. chart.data(this.chartData);
  27. chart.axis("time", {
  28. tickLine: null
  29. });
  30. // chart.legend({
  31. // position: "bottom"
  32. // });
  33. chart.tooltip({
  34. shared: true,
  35. showMarkers: false
  36. });
  37. chart.interaction("active-region");
  38. chart
  39. .interval()
  40. .adjust("stack")
  41. .position("time*value")
  42. .color("type", ["#F3CC1C", "#1890ff", "#6190FF", "#36CFAA"]);
  43. chart.render();
  44. }
  45. }
  46. };
  47. </script>
  48. <style scoped>
  49. </style>