首页 > 解决方案 > 如何使用 D3 和 Vue 本地化和格式化刻度

问题描述

vue-i18n用来格式化日期,如下所示:

const setDateTimeFormats = {
  short: {
    year: 'numeric',
    month: 'long',
    day: 'numeric',
  },
};

export const dateTimeFormats = {
  en: setDateTimeFormats,
  ja: setDateTimeFormats,
};

然后像这样调用它:

checkedOn() {
  return this.$d(moment(checkedOn), 'short');
},

但我不知道如何在同一个项目中使用 D3 本地化和格式化刻度。

这是与蜱有关的一点(仅显示从Jan现在到现在 的月份Jan Feb Mar Apr May Jun Jul Aug Sep:)

const x = scaleTime()
  .domain([moment('2020-01-01').toDate(), moment().toDate()])
  .range([0, width]);

svg.append('g')
  .attr('class', 'xaxis')
  .attr('transform', `translate(0, ${height})`)
  .call(axisBottom(x).tickFormat(timeFormat('%b')));

标签: vue.jsd3.jsmomentjs

解决方案


推荐阅读