0

I have such an example in which I would like to change the series of data on the xaxis along with changing the formatting:

ApexCharts.exec("chartID", "updateOptions", {
 xaxis: {
    type: "datetime",
    categories: dates_string_array,
    tickAmount:5,
        labels: {
      show: true,
        rotate: -45,
    format: 'yyyy-MM-dd'}
  },
});

The categories substitution corrects (it is an array with dates as string) however, this formatting format: 'yyyy-MM-dd' still doesn't work - the format is exactly what the dates in the dates_string_array are in. In this case, do I need to use formatter to overwrite these values?

An example of default format one of array elements: 2022-01-01 10:00

I would like to format it like this: 2022-01-01

DeepSea
  • 305
  • 2
  • 15
  • If you talking about formatting categories in tooltip then yes, you need to use `formatter ` – Patryk Laszuk Jul 14 '22 at 10:07
  • @PatrykLaszuk Yes, that's exactly what it tried to do. Category input is an array of dates in the format `"yyyy-MM-dd HH:mm"`, but when trying to call something like this: `formatter: function (val) {return val.toString()}` such an error appears: `TypeError: Cannot read properties of undefined (reading 'toString')` this is some weird format, I have no idea what kind of format – DeepSea Jul 14 '22 at 10:25
  • 1
    Add `if(val)` before return – Patryk Laszuk Jul 14 '22 at 13:00
  • @PatrykLaszuk Yes you are right, just this condition was enough and formatting on xaxis works correctly. What do I need to do if the tooltip I would still like in the previous format? The xaxis in `yyyy-MM-dd` format as currently and the tooltip `yyyy-MM-dd HH:mm`? I tried with `tooltip` `x: {format: "yyyy-MM-dd HH:mm"}`, but it doesn't work. Any idea? – DeepSea Jul 14 '22 at 13:45
  • Try `formatter` instead `format`, [this](https://stackoverflow.com/q/10632346/16537039) might help you with formatting – Patryk Laszuk Jul 14 '22 at 19:06

0 Answers0