Shinobichart axis padding - android

I am not able to make the xAxis in my Shinobichart look good. The right axis label is cut in half (see picture). xAxis.setRangePaddingHigh does not work. I assume this has to do with me using a custom date range. Please help!
DateRange dateRange = new DateRange(oldDate, today);
xAxis.setDefaultRange(dateRange);
xAxis.setTickMarkClippingModeHigh(TickMark.ClippingMode.TICKS_AND_LABELS_PERSIST);
xAxis.getStyle().getTickStyle().setMinorTicksShown(true);
xAxis.getStyle().getTickStyle().setMajorTicksShown(true);
xAxis.getStyle().getTickStyle().setLabelsShown(true);
DateFrequency test = new DateFrequency(30, DateFrequency.Denomination.MINUTES);
xAxis.setRangePaddingHigh(test);
shinobiChart.setXAxis(xAxis);

As you suspect, when a default range is set on an Axis any range padding is ignored. The API docs don't really mention this so we'll look to update them in the future!
Have you tried the other ClippingModes? The one you are using here will display the tick labels even if it means they will be partially cut off.
The TICKS_PERSIST mode would still show the tick mark line at the far right of the axis but as the label would be cut off it won't be shown. The NEITHER_PERSIST mode on the other hand won't show either the label or the tick mark line.
Depending on when you set the mode you may need to call shinobiChart.redrawChart() though here it looks like you won't have to as you're doing it before you add the axis to the chart.
Finally, if you want more control over how the tick marks are draw you can use the ShinobiChart.OnTickMarkUpdateListener and/or the ShinobiChart.OnTickMarkDrawListener (along with ChartUtils to get some of the default behaviour).
Full disclosure - I work for shinobicontrols

Related

MPAndroidChart set current visible X axis

Using MPAndroidChart, I'm struggling to figure out how to set the current visible x axis values. The use case is simple and I would have thought very common, so I'm sure I must be missing some function which can do this:
Say you have a chart with x axis values 1-100
A user zooms and pans a chart so that the range 60-80 is visible. I want to store these values, so that tomorrow when the user re-launches the app, I can restore the exact viewing state (60-80)
Storing the values is really easy - you can simply call chart.lowestVisibleX and chart.highestVisibleX to get the x axis values. But how do I set them on a new instance of the chart? Unfortunately there doesn't seem to be a chart.setHighestVisibleX or chart.setLowestVisibleX.
This previous question / answer is nearly, but not quite, what I need. The suggestion is to use a combination of chart.moveViewToX(60) and chart.setVisibleXRangeMaximum(20). However as the docs for setVisibleXRangeMaximum state:
Sets the size of the area (range on the x-axis) that should be maximum
visible at once (no further zooming out allowed)
I don't want to prevent further zooming, which is what this does. There must be a way to set the zoom level without actually restricting further zooming - but I can't figure it out. Any suggestions?
Thanks
Just to answer my own question, I decided to workaround this issue by resetting the X range maximum after calling moveViewToX. This appears to work. So the solution would be:
chart.setVisibleXRangeMaximum(20)
chart.moveViewToX(60)
chart.setVisibleXRangeMaximum(100)

How to ensure space between labels MPAndroidChart

I am creating a line chart using MPAndroidChart, all is working great, but I've noticed that at the labels often become bunched up. I know there is a way to prevent this (I've seen other apps that don't have this issue,) but I don't know what setting to enable.
There are a couple of ways you could make the labels fit better.
Decrease the text size of the X axis labels with mChart.getXAxis().setTextSize(float)
Set a label count limit for the X axis using mChart.getXAxis().setLabelCount(int). This should work fine, as you are already not showing one label per data point.
Change the date format of your label.
Some, all or none of these might help you, depending on your requirements. Good luck!

WilliamChart Axis color & don't start at 0

I'm using the WilliamChart library for Android.
Everything works perfect and now I want to set the axis color to white. I've tried with the following but that didn't change it:
chartview:chart_axisColor="#fff"
How can I change the axis color?
My second problem is that I have a chart where the numbers are higher than 500 but all about the same. So now I have all the dots of my line on top since the chart starts at 0.
Can WilliamChart figure out my lowest and highest number and fit the points in between?
I think I saw this somewhere but I couldn't find it in the example or the docs.
About the color, you're doing it right, so assuming you also defined:
xmlns:chartview="http://schemas.android.com/apk/res-auto"
it should work (if not raise the issue on github). The sample application has an example of it as well.
If you don't define any minimum and maximum value the library must calculate what they are. Perhaps you are defining them yourself with setAxisBorderValues and in that case the lib assumes those as correct.

Negative Barchart with Androidplot

I'm using the Androidplot library to plot a Barchart to display something.
The range of my values are -40 till +40.
How can I plot a bar to the negative side? I just want to center the zero on the y-axis in the middle and the bars should growing up or down, if the value is positiv of negativ. My bars are growing from the lower bound upwards. It should look like this:
That works for me:
plot.centerOnRangeOrigin(0);
plot.setRangeLowerBoundary(0,BoundaryMode.AUTO);
Where plot is a instance of XYPlot.
Negative bar support has recently been added to Androidplot 0.6.2; you'll need to use the latest development version to get it (it's very stable).
Once you have the correct version of Androidplot you can use Maria Reina's suggestion to enable the display of negative values. Here's how I'm doing it in the screenshot below:
plot.setUserRangeOrigin(0);
plot.setRangeBoundaries(0, BoundaryMode.AUTO, 0,BoundaryMode.AUTO);
Note : There is currently a bug where if you are using overlay mode with 2 or more series and have negative bars, the overlay order of negative bars is reversed, causing the smaller negative values in a bargroup to be obscured by the larger ones. If your goal is simply to reproduce the image above though then you should be fine.
That's a great question. I think there's no way to do that with the current version of AndroidPlot (0.6.0) with a single series of values.
I created a workaround in my project. I know it's not perfect, but it works: create two series that overlap, one in green and one in the background color. Suppose you have your currentValue to draw..
if (currentValue>=0) {
greenRes[i] = Float.valueOf(currentValue);
coverRes[i] = Float.valueOf(0);
}
else {
greenRes[i] = Float.valueOf(0);
coverRes[i] = Float.valueOf(currentValue);
}
In this way you always have the green bar starting from the zero axis and going up or down.

Using achartengine to draw a bar graph but my last bar is squeezed out?

When drawing the bar chart I end up with the last bar being squeezed out of frame, regardless of whether the orientation of the x-axis is vertical or horizontal. I have disabled panning so maybe this has something to do with it but enabling it is not an option.
It looks like this:
I've tried changing the margins/bar width and adding a dummy empty value to the end of the dataset, but the problem persists. Is there a setting somewhere to fix this?
EDIT - I found I can actually add a dummy empty entry at the end of the series and this fixes the problem (long story short I forgot I was limiting the length of the x-axis), but this is a rather ugly solution so if anybody knows of a better one please don't hesitate to inform us!
Thanks in advance!
Half of the bar is outside of the viewable part of the chart.
Set setXAxisMax to your series .getMaxX +1 or 0.5 or equivalent for the YAxis usually fixes this kind of problems.
If you add a dummy value you might get a tiny line at the bottom of the graph.

Categories

Resources