javascript - ChartJs多轴图表显示不同的标签底部和顶部

标签 javascript chart.js

我正在使用 Chart.js 来渲染图表。我使用的多轴图表的 y 轴从 -100 到 100,底部有 x 轴,带有黑/白等标签,如果值 > 0,则表示黑色,如果值 <0,则表示白色。

我想将图表上的“黑色”标签和底部的“白色”标签分开,我该怎么做?

var other = new Chart(ctx5,{
        type: 'radar',
        data: {
              labels:other_data_label,
              datasets:[{
                      data: behaviour_fixed_array, //processing_information_data,
                      backgroundColor: 'rgba(102, 187, 158,0.2)',
                      borderColor: 'rgb(102,187,158)',
                      pointBackgroundColor:'rgb(67, 122, 103)',
                        },
                        {
                        backgroundColor: 'rgba(188,101,47,0.2)',
                        borderColor: 'rgb(168,101,47)',
                        pointBackgroundColor:'rgb(155, 21, 6)',
                        data: []
                        }]
              },
        options: {
              legend: {
                  position: 'top',
                  display: false
              },
              scale: {
                    display: true,
                    ticks: {
                          beginAtZero: true,
                            }
                     },
              responsive:true,
              maintainAspectRatio: true,
                 }
          });
     //end graph 5//

最佳答案

您需要做两件事: 1.为每个数据集分配一个xAxis 2.为选项对象内部的xAxes设置不同的选项

我在这里开始了一个示例 - 请注意 xAxesID 和刻度数组

data: {
  labels:other_data_label,
  datasets:[{
              data: behaviour_fixed_array, //processing_information_data,
              backgroundColor: 'rgba(102, 187, 158,0.2)',
              borderColor: 'rgb(102,187,158)',
              pointBackgroundColor:'rgb(67, 122, 103)',
              xAxisID: 'x-axis-1'
            },
            {
              backgroundColor: 'rgba(188,101,47,0.2)',
              borderColor: 'rgb(168,101,47)',
              pointBackgroundColor:'rgb(155, 21, 6)',
              data: [],
              xAxisID: 'x-axis-2'
            }]
          },
          options: {
            legend: {
              position: 'top',
              display: false
            },
            scales: {
              xAxes: [{
                display: true,
                position: 'top',
                id: 'x-axis-1'
              },
              {
                display: true,
                position: 'bottom',
                id: 'x-axis-2'
              }]
            },
            responsive:true,
            maintainAspectRatio: true,
          }
        });

关于javascript - ChartJs多轴图表显示不同的标签底部和顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49560623/

相关文章:

javascript - YouTube 暂停、播放和停止不起作用

javascript - 构建 Chart.js master - 生成的 .js 出现错误

javascript - 删除请求不起作用

javascript - SVG/HTML 5 Canvas - 圆形图案位移,stripe.com 方法

javascript - chart.js 删除悬停效果

javascript - 如何在 chartJS 中定位 yAxes 标签

javascript - Chart.js CoffeeScript 找不到变量

chart.js - Charts.js 会自动添加逗号作为千位分隔符,但本不该添加

javascript - 如何在 Angular 2 类型脚本中附加带有参数的 url?

javascript - 浏览器端 CSS 抽象语法树生成器。 (JavaScript 但不是 Node)