【问题标题】:How to only have a Y axes representing data in chart.js如何在chart.js中只有一个表示数据的Y轴
【发布时间】:2018-05-15 20:02:45
【问题描述】:

我想在 Chart.js 中将“你上一场比赛的进球次数”数据绘制成折线图。

我有一个 userGoalTime 数组,例如[34, 80, 90] 我有一个对手GoalTime 数组,例如[39, 42]

Y 轴将包含所有分钟,但我不想要 X 轴上的任何内容。问题是我认为 chart.js 必须用 X 轴上的东西来表示一个值(如果这有意义的话)

谁能解释一下如何仅使用 Y 轴在图表上绘制点?

尝试的解决方案:

  let ctx = canvas.getContext('2d')
  let lineChart = new Chart(ctx, {
    type: 'line',
    data: {
      labels: ['0', '1'], // I DON'T WANT THE X AXES TO REPRESENT ANYTHING
      datasets: [{
        label: 'For',
        backgroundColor: '#85CE36',
        fill: false,
        showLine: showLine, // this is true
        borderColor: '#85CE36',
        data: userGoals // The array as described
      }, {
        label: 'Against',
        backgroundColor: 'red',
        fill: false,
        showLine: showLine, // this is true
        borderColor: 'red',
        data: opponentGoals // The array as described
      }
      ]
    },
    options: {
      responsive: true,
      title: {
        display: true,
        text: nameOfStat
      },
      tooltips: {
        mode: 'index',
        intersect: false
      },
      hover: {
        mode: 'nearest',
        intersect: true
      },
      elements: {
        point: {
          pointStyle: style
        }
      },
      scales: {
        xAxes: [{
          display: false // Not really what I am looking for... This just hides the X axes but that's it
        }]
      }
    }
  })

谢谢。

【问题讨论】:

    标签: javascript chart.js axes


    【解决方案1】:

    改成这个

    new Chart(ctx, {
        ...
        options:
        {
            scales:
            {
                xAxes: [{
                    display: false
                }]
            }
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-31
      • 2022-11-02
      • 2022-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多