Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datetime axis doesn't respect "tickAmount" #89

Closed
JCQuintas opened this issue Sep 12, 2018 · 11 comments
Closed

Datetime axis doesn't respect "tickAmount" #89

JCQuintas opened this issue Sep 12, 2018 · 11 comments

Comments

@JCQuintas
Copy link
Contributor

Datetime axis doesn't respect any given "tickAmount"

Example:
https://codesandbox.io/s/w0rxpzwznw

@junedchhipa
Copy link
Contributor

Yes, as of now - the timescale ticks calculation is totally dependent on how many days/months is the gap and based on that - tickAmount is dynamically calculated discarding the option set by the user.

One way is to set the options.xaxis.formatter function and then it will take into account the tickAmount set by the user. One disadvantage when using this function is you get the same result whether the x-axis timescale difference is years/months/days/hours

xaxis: {
  tickAmount: 6,
  labels: {
    formatter: function(val, timestamp) {
      return moment(timestamp).format("DD MMM YYYY");
    }
  }
},

@JCQuintas
Copy link
Contributor Author

I see, is this documented somewhere? We could have a least a hint for that.

@junedchhipa
Copy link
Contributor

Just added.
https://apexcharts.com/docs/options/xaxis/#tickAmount

@pnemi
Copy link

pnemi commented Sep 13, 2018

Is there any possibility how to achieve this behavior then, please? I just want 3 ticks (start date, middle date, end date).
screen shot 2018-09-12 at 13 55 58

@junedchhipa
Copy link
Contributor

You may try setting the xaxis.tickAmount: 4 along with xaxis.labels.formatter as suggested above.

xaxis: {
  tickAmount: 6,
  labels: {
    formatter: function(val, timestamp) {
      return moment(timestamp).format("MMM YY");
    }
  }
},

You may not get the labels exactly on the places you described (start/middle/end) but it will be close to it.

@jatindumka
Copy link

can heat map have a datetime axis?????

@ayaz2929
Copy link

ayaz2929 commented Jul 7, 2020

can we set the resolution, like we want to show data of 5 years then 3 years 1 month.. is there any option we can set it from chart

@joykliu
Copy link

joykliu commented Jul 29, 2020

@junedchhipa I was able to control the number of ticks by following your suggestion, however two things happened.
1, the chart's grid lines disappeared:

    grid: {
      xaxis: {
        lines: {
          show: true
        }
      },
      yaxis: {
        lines: {
          show: false
        }
      },
      borderColor: "#B0B0B0",
      position: "front"
    },
  1. the timestamp param of formatter is inaccurate and it is actually the index of that label rather than a timestamp

Screen Shot 2020-07-28 at 8 20 05 PM

@and-mine
Copy link

How can i show regular interval of time in y axis. for eg. 10:30 , 11:00, 11:30 . In my case its populating automically based on data passed to chart. Iam usig range bar chart. Please help me .

@FrenchyProds
Copy link

How can i show regular interval of time in y axis. for eg. 10:30 , 11:00, 11:30 . In my case its populating automically based on data passed to chart. Iam usig range bar chart. Please help me .

What does your data look like ? If your timestamps are not populating your data following the half an hour trend you seem to want to produce, then unfortunately I don't think there's a way to display half an hour steps on your xaxis.

However if your timestamps are 30 minute steps, then you need to do as described above :

  • Create an xaxis label formatter
  • Specify the tickAmount for your xaxis to match what you wish to display. If you have 10x 30 minute steps, then set the tickAmount to 11

@YFarias
Copy link

YFarias commented Dec 10, 2024

Guys, I'm using vue.js, and you helped me too much with the comments. I'm pasting my piece of code, maybe it could help someone else. In my case, the user could "zoom in" the chart intervals. That's why I calculated the max and min and replaced the format to show hours.

   xaxis: {
		type: "numeric",
		min: this.minX - margin,
		max: this.maxX + margin,
		tickAmount: 7,
		tickPlacement: "between",
		labels: {
			formatter: function(val, timestamp, opt) {
				const formatAvailabe = ["DD MMM", "HH:mm"];
				let _max = opt?.w?.config?.xaxis.max;
				let _min = opt?.w?.config?.xaxis.min;

				if (!_max || !_min) return "";

				if (_max - _min < 24 * 60 * 60 * 1000) {
					return moment(val).format(formatAvailabe[1]);
				} else {
					return moment(val).format(formatAvailabe[0]);
				}
			},
			show: true,
			minHeight: 70,
			rotateAlways: false,
			maxTicksLimit: 7
		}
     }

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants