Negative Barchart with Androidplot - android

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.

Related

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!

Shinobichart axis padding

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

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.

MPAndroidChart Bar chart bar title rotation

I have problem with displaying of bars value. I want to display multiply bar chart, but when values are similar, then text is not very good readable :(.
See picture here.
Do you have some ideas for improving this?
Thanks
I would suggest that you either develop some kind of mechanism that disables the drawing of values if they are too close to each other.
Other than that, you could:
disable drawing the values in general
reduce the text size drastically
reduce the number of decimals
use the ValueFormatter interface and disallow drawint 0 values

GraphView y-axis label flicker and space on top with empty title?

Two questions regarding the GraphView library.
1) With manual setNumVerticalLabels set when switching from scrolling to scaling and vice versa, that the labels for my y-Axis change it's position. In scrolling mode they are closer together and in scaling mode a bit further apart.
In case of having the number of labels set automatically, the number of labels also changes between the two modes.
Is this a known bug? Is there any way to get around that behavior?
2) Is it possible to claim the space above the graph for the graph if the title is left empty?
Thanks for any help!
1) that is because your labels could need more space. You have 2 options:
a) set a fixed width for the vertical labels
or b) make sure that the labels have a fixed/limited count of characters via custom label formatter.
2) this is not possible with GraphView 3.x, but in GraphView 4.0 this is be fixed.

Categories

Resources