Chartjs中的叠加条形图

ca1c2owp  于 2024-01-07  发布在  Chart.js
关注(0)|答案(1)|浏览(281)

我正在使用的图表JS图表与类型栏,并试图创建重叠的酒吧。它必须是3酒吧为一个日期,互相重叠。
想法:

  • 具有最大值的条应该具有(z-index:0),它将是该列的高度
  • 值较低条形图z指数应该较大,以便我们可以看到

有一个正确顺序,但它适用于所有的小节集,所以一些小节可以完全重叠在另一个小节上。
是否可以使用chartJS?或者我应该使用另一个库?
x1c 0d1x的数据

omvjsjqw

omvjsjqw1#

你可以用highchart,有很多变化你可以尝试
这里有一个这样的例子:

  1. Highcharts.chart('container', {
  2. chart: {
  3. type: 'column'
  4. },
  5. title: {
  6. text: 'A basic column chart',
  7. align: 'left'
  8. },
  9. xAxis: {
  10. categories: ['USA', 'China', 'Brazil', 'EU', 'India', 'Russia'],
  11. crosshair: true,
  12. accessibility: {
  13. description: 'Countries'
  14. }
  15. },
  16. yAxis: {
  17. min: 0,
  18. title: {
  19. text: '1000 metric tons (MT)'
  20. }
  21. },
  22. tooltip: {
  23. valueSuffix: ' (1000 MT)'
  24. },
  25. plotOptions: {
  26. column: {
  27. borderWidth: 0,
  28. stacking: "overlap"
  29. }
  30. },
  31. series: [
  32. {
  33. name: 'Corn',
  34. data: [406292, 260000, 55000, 68300, 27500, 14500]
  35. },
  36. {
  37. name: 'Wheat',
  38. data: [51086, 136000, 107000, 141000, 107180, 77000]
  39. }
  40. ]
  41. });
  1. .highcharts-figure,
  2. .highcharts-data-table table {
  3. min-width: 310px;
  4. max-width: 800px;
  5. margin: 1em auto;
  6. }
  7. #container {
  8. height: 400px;
  9. }
  10. .highcharts-data-table table {
  11. font-family: Verdana, sans-serif;
  12. border-collapse: collapse;
  13. border: 1px solid #ebebeb;
  14. margin: 10px auto;
  15. text-align: center;
  16. width: 100%;
  17. max-width: 500px;
  18. }
  19. .highcharts-data-table caption {
  20. padding: 1em 0;
  21. font-size: 1.2em;
  22. color: #555;
  23. }
  24. .highcharts-data-table th {
  25. font-weight: 600;
  26. padding: 0.5em;
  27. }
  28. .highcharts-data-table td,
  29. .highcharts-data-table th,
  30. .highcharts-data-table caption {
  31. padding: 0.5em;
  32. }
  33. .highcharts-data-table thead tr,
  34. .highcharts-data-table tr:nth-child(even) {
  35. background: #f8f8f8;
  36. }
  37. .highcharts-data-table tr:hover {
  38. background: #f1f7ff;
  39. }
  1. <script src="https://code.highcharts.com/highcharts.js"></script>
  2. <script src="https://code.highcharts.com/modules/exporting.js"></script>
  3. <script src="https://code.highcharts.com/modules/export-data.js"></script>
  4. <script src="https://code.highcharts.com/modules/accessibility.js"></script>
  5. <figure class="highcharts-figure">
  6. <div id="container"></div>
  7. </figure>

您可以在API指南中探索许多选项,并根据需要进行调整https://api.highcharts.com/highcharts/global
希望能帮上忙。

展开查看全部

相关问题