How to ensure space between labels MPAndroidChart - android

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!

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)

MPAndroidChart - Linechart - shrink part of the graph with no X values

Is it possible to do something like this:
? I have in the app LineChart with the time values (seconds) on X axis and temperature on Y axis.
And it's possible that I don't have a data for some bigger time interval (day and more for example) and it will not be very user frinedly if user has to swipe so much back. So I want to create this "shortcut" or somehow "delete" empty part of the graph (with no X values). Is is possible? Maybe there don't have to be this gap but I need to contine from time "10:30" to time "14:20" in one graph without big scrolling.
Do you have some suggestions?
Have a look at this and
this
There is a way to get a continued graph and don't have an empty gap in between however the way you are looking for kind of seems like a drag because even though you explicitly dont add the empty data to dataset, it is meant to work like a continued thing.
Hope this helps, cheers

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.

Achartengine bardiagrams with too high values

I've worked large time with AChartEngine and now I know to plot a special bar diagram. Most of the bars are small. But two of them are much bigger than the others. If I use the function "setXAxisMax", the small bars are ridiculous small in the chart.
My question is, is there any way to plot the axis and some of the bars in two parts using ACharEngine? Or is it only possible to plot continuous bars?
Thanks in advance.
I have also had the chance of using a few graphing engines and i haven't
come across any that allows one to draw a single bar as two parts.In any case it will be very misleading when reading the values of the graphs.One solution which i use frequently would be to set a min value for the axis(y-axis) so that the values don't start from zero.that way you reduce the range significantly.

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.

Categories

Resources