[Android] How can I affect the time that Shinobi chooses for Major ticks?


#1

I have an application that looks like this:

Charting Application 

As shown, the times that Shinobi is choosing seem to be every hour, but starting at 10 seconds after the 21 minute of the hour. It’d be much nicer if the times chosen were better, perhaps the top of each hour, or every fifteen minutes from the top of each hour. How would I control this in my Android application? If you can’t see the image, try clicking on it, for a link to the image.

Thanks, in advance.

-Neal


#2

I figured out that if I use the mTimeAxis.setMajorTickMarkValues(listOfDates); I am able to set the major ticks to whatever I want to. One remaining question I have, though, is how do I also display minor ticks when setMajorTickMarkValues is used?


#3

Hi Neal,

I’m glad you found a way to add the tick marks you wanted to your axis! Currently in ShinobiCharts for Android, unlike our iOS counterpart, we don’t support the setting of an anchor point for tickmarks on an axis. This would be a way of ensure the ticks fell on the top of each hour etc. It is on our roadmap and we prioritise features based on customer feedback so I’ll certainly make a note of your need for this.

Obviously explicitly setting the tick mark values is one way of achieving this (and may be the best way in your case). You may also find setting a default range on the axis that starts, for example, on the top of every hour has the same effect although this does depend on how you’re making use of default ranges and how panning and zooming is restricted within them.

We don’t provide a similar method for adding minor ticks at specific points, and neither in fact does the iOS version. However, we do provide a callback interface called ShinobiChart.OnTickMarkDrawListener which provides access to the canvas upon which the tick marks are drawn. You’re entering the more advanced usage realm of our library here but you may find this helpful for adding some minor ticks. Note that at the point the callback method is called you can successfully use the Axis.getPixelValueForUserValue() method (should you need to) as the chart will already have been laid out (using it before the chart is laid out will return incorrect, values).

See the ShinobiChart.OnTickMarkDrawListener API docs.

Kind regards,

Patrick


#4

Thanks Patrick,

I just experimented with this onTickMarkDrawListener as you suggest. This has the effect of requiring the listener to draw all of the major ticks in the listener callback. Is there a way to access the default tick drawing code, so that I could call the default code during the callback as well as adding minor ticks?

Cheers,

Neal


#5

Hi Neal,

Yes you’re absolutely right, with the OnTickMarkDrawListener you have to perform all the drawing of the tick marks (including the labels) yourself (so an implementation that does nothing will mean no ticks are drawn).

As such we’ve provided a utility class called ChartUtils which has various static methods that provide the default tick drawing code. So for example you could do the following:

if (tickMark.isLineShown()) {
    ChartUtils.drawTickMarkLine(canvas, tickMark);
}

if (tickMark.isLabelShown()) {
    ChartUtils.drawText(canvas, tickMark.getLabelText(), tickMark.getLabelCenter().x,
            tickMark.getLabelCenter().y, tickMark.getLabelPaint());
}

in order to get the default tick mark drawing behaviour. Note, if you tick labels have backgrounds you’d need to include a line for drawing them as well.

See these API docs for more info.

Kind regards,

Patrick