首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么x轴不增加‘月’chart.js。另外,XAxis没有获得头衔

为什么x轴不增加‘月’chart.js。另外,XAxis没有获得头衔
EN

Stack Overflow用户
提问于 2022-03-23 23:15:10
回答 1查看 26关注 0票数 -1

https://water.sas.usace.army.mil/chart.htm https://water.sas.usace.army.mil/chart.png See the Code Above, (View Source) The code builds a time-series chart. The scales section has unit set to month, however chart does not display with monthly increment on x axis.

Also Y axis will not display title.

EN

回答 1

Stack Overflow用户

发布于 2022-03-24 04:21:39

主要问题是config没有正确格式化,options.plugins没有被}关闭,因此Chart.js不考虑整个scales部分。

此外,您还应该定义一个time.parser,让日期适配器知道如何解析提供的日期字符串。

要小心地为time.parsertime.displayFormats选择正确的time.displayFormats

因此,如果您按照以下方式定义config,那么它应该可以工作。

代码语言:javascript
复制
const config = {
  type: 'line',
  data: data,
  options: {
    responsive: true,
    plugins: {
      legend: {
        display: true,
        position: 'bottom'
      },
      title: {
        display: true,
        text: "HARTWELL PROJECT",
        font: {
          size: 20
        }
      },
    },
    scales: {
      x: {
        type: 'time',
        time: {
          parser: 'MM/dd/yyyy',
          unit: 'month',
          displayFormats: {
            month: 'MMM yyyy'
          }
        },
        title: {
          display: true,
          text: 'Date'
        }
      },
      y: {
        title: {
          position: 'left',
          display: true,
          text: 'Elevation (FT-MSL)'
        }
      }
    },
    chartAreaBorder: {
      borderColor: 'black',
      borderWidth: 10,
      //borderDash: [5, 5],
      borderDashOffset: 5
    },
    imgPlugin: {}
  },
  plugins: [chartAreaBorder, imgPlugin, GradientBgPlugin]
};
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71595205

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档