LoginSignup
0
2

More than 3 years have passed since last update.

react-apexchartsで日付を「月/日(曜日)」のフォーマットに変えたい

Posted at

参考データ

うーん、「6/1(月)」って表示できないかな。

現在のコード

xaxis: {
  type: "datetime",
  axisBorder: {
    show: true,
    color: theme.palette.divider
  },
  axisTicks: {
    show: true,
    color: theme.palette.divider
  },
  categories: categories,
  labels: {
    format: 'MM/dd(ddd)',
    style: {
      colors: theme.palette.text.secondary
    }
  }
},

公式を見てみる。

公式情報

Datetime ApexCharts.js

んー、曜日の日本語表記はなさそう。

 とりあえずこれで対処

const weekday = ["", "", "", "", "", "", ""];
/*
…
*/
labels: {
  formatter: function (value, timestamp) {
    var date = new Date(timestamp);
    return date.getMonth() + 1 + '/' + date.getDate() + '(' + weekday[date.getDay()] + ')';
  }
}

結果

これで良しとする。

追伸

なにか他に良いコードがあればご教示いただけましたら幸いです。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2