Can you use tickSize if you are also providing custom ticks?

514 views
Skip to first unread message

Irl

unread,
Jan 15, 2013, 2:28:10 PM1/15/13
to flot-...@googlegroups.com
I'm using custom ticks.  For example:

ticks: [[1,'Q1-2000'], [2,'Q2-2000'], [3,'Q3-2000'], [4,'Q4-2000'], [5,'Q1-2001'], [6,'Q2-2001'], [7,'Q3-2001'], [8,'Q4-2001'], [9,'Q1-2002'], [10,'Q2-2002'], [11,'Q3-2002'], [12,'Q4-2002']]

When I attempt to use tickSize, there is no effect. For example if I used tickSize: 4, I would think only Q4-2000, Q4-2001, Q4-2002 would show up.  However, all of the ticks show-up.  Is there a way to utilize tickSize and ticks together? I'm trying to avoid providing a bunch of other logic to accomplish the same goal.

DNS

unread,
Jan 15, 2013, 2:46:15 PM1/15/13
to flot-...@googlegroups.com
No; if you provide ticks then Flot uses those rather than generating its own.  What is your goal?

Irl

unread,
Jan 15, 2013, 4:03:30 PM1/15/13
to flot-...@googlegroups.com
I'm creating charts from data that can have frequencies of Monthly, Quarterly, and Yearly.  I'd like to use the format of 1-2000, Q1-2000, and 2000.  I'm getting data dynamically from an api.  First, I pull and can determine the frequency of the data and provide the appropriate formats through ticks.  My issue is when there are too many datapoints (e.g. would crowd the x-axis) I want to be able to only show some of the ticks.

If this is confusing I can provide more information.

Karl Quinsland

unread,
Jan 15, 2013, 4:11:38 PM1/15/13
to flot-...@googlegroups.com
I understand what you're trying to do.  A project I'm working on uses similar functionality only i work on hours / days / months / years type of scale.
You will have to set up a function that generates the ticks automatically and give them to flot as an array.  *or* you could use a custom tick formatter function.  Be aware, though, that if you use a custom tick formatter, you will not be able to tell flot to label the tick with 'nothing'.  You can return null with the tick formatter, but flot will just display "undefined" for each tick. 

I think your best option is the first one.  a function that looks and determines which labeling style is needed and then computes where the ticks should go (eg, every X data points) and what each tick should be formatted as.  This information is used to generate an array of ticks which is fed back to flot.


good luck!

-- Karl

DNS

unread,
Jan 15, 2013, 4:55:52 PM1/15/13
to flot-...@googlegroups.com
Karl's advice is the way to go, although I would probably try the custom formatter option first.  The latest dev version supports quarters in the date-format spec, so you might not even need to write a function.  If you haven't already, try getting the latest master and see if the time-axis plugin gives you what you want.

Irl

unread,
Jan 15, 2013, 5:11:56 PM1/15/13
to flot-...@googlegroups.com
Thanks Karl, 

I'm going to go with option 1, I just did a test and I didn't realize you could put in an empty string and therefore not display anything in a tick array.  For example, if I want to have a tick displayed for datapoints 1,4,7,10,13,16, and 19, my array would look something like: 

ticks: [[1,'2000'], [2,''], [3,''], [4,'2003'], [5,''], [6,''], [7,'2006'], [8,''], [9,''], [10,'2009'], [11,''], [12,''], [13,'2012'], [14,''], [15,''], [16,'2015'], [17,''], [18,''], [19,'2018'], [20,'']]

Thanks again for your help.

Irl

unread,
Jan 15, 2013, 5:13:25 PM1/15/13
to flot-...@googlegroups.com
Sounds good, I'll check that out.

ka...@karlquinsland.com

unread,
Jan 15, 2013, 5:29:44 PM1/15/13
to flot-...@googlegroups.com
Yep, that's precisely what I meant for a function to auto generate. Glad you got it all sorted.

--Karl
Sent via BlackBerry

From: Irl <irln...@gmail.com>
Date: Tue, 15 Jan 2013 14:11:56 -0800 (PST)
Subject: Re: Can you use tickSize if you are also providing custom ticks?
Reply all
Reply to author
Forward
0 new messages