How to set the label count for X axis in LineChartView? - ios

In my data, I have hundreds of values for the x-axis, but I want to show only 6 or 7 of them at equal intervals so that my whole range of x-axis values are covered, but I am facing an issue as I am not able to show a limited number of values on the x-axis . I tried these
lineChartView.xAxis.spaceMin = 4
lineChartView.xAxis.spaceMax = 7
lineChartView.xAxis.xOffset = 6
lineChartView.xAxis.labelCount = 6
, but it is not working .Here is my screenshot for the display

The axis property granularity is used to specify the minimum interval between axis values. The default value is 1. Currently in my app i have it set to 0.5 to force all values to be displayed, but I only have 10 or so on the chart at once.
chartView.xAxis.granularity = 0.5
Perhaps setting this to a higher value will help you.

Related

X-axis action strange - Charts iOS

I'm using the Charts library on iOS, but I'm having troubles with one of my charts in my TableView. The X-axis looks strange, and I loose resolution in my data. Here is how it currently looks:
My data is typically between 900 and 1100.
I configured the chart like this:
let dataSet = LineChartDataSet(values: entries, label: "")
dataSet.drawCirclesEnabled = false
dataSet.lineWidth = 2
dataSet.mode = .horizontalBezier
dataSet.colors = UIColor.gray
dataSet.drawValuesEnabled = false
let lineChartData = LineChartData(dataSets: [dataSet])
self.chartEntries.append(lineChartData)
Any ideas on why my X-axis looks like this? My others charts look fine and dandy.
The chart looks fine, since it's trying to squeeze your data that's around value 1000 into a very small space. If you have a look at the MPAndroidChart lib wiki, you can see that you can adjust the min and max range per axis, so you can effectively zoom in closer to your values to better see the distribution:
setAxisMaximum(float max): Set a custom maximum value for this axis.
If set, this value will not be calculated automatically depending on
the provided data.
setAxisMinimum(float min): Set a custom minimum value for this axis.
If set, this value will not be calculated automatically depending on
the provided data.
It would look something like:
graph.yAxis.axisMinimum = 900
graph.yAxis.axisMaximum = 1100

iOS Charts library and LineChart xAxis

I'm trying to create a LineChartView with values representing expenses for the current quarter. I need to print months and days with a custom number of labels for the xAxis. Unfortunately the LineChart is generating a set of entries that doesn't suit my needs and I cannot change them. I need the grid lines at my custom positions that are the first day of the month and a set of days for the month and I want them at specific positions not where the LineChart wants. I've checked the code and seen that the entry values for the xAxis are calculate in XAxisRenderer.computeAxisValues and it looks like I have no way to specify their number and positions. The number of labels that I set it is not taken into account ... and I do not have time to customise it.
There are 2 ways might achieve what you needed:
Set the number of labels for x-axis, for example,
let xAxis = chartView.xAxis
xAxis.labelCount = 7
//xAxis.drawLabelsEnabled = true
Through this, exactly 7 grid lines as will be drawn, if you set
drawLabelsEnabled as false, the min and max lines will be added in
additional to those 7
Use limit lines
You can disable the drawing of grid lines, and use limit lines
instead. In this way, you can draw line for whatever values you
need, for example,
let limitLine = ChartLimitLine(limit: xValue, label:
labelForThisLine)
limitLine.lineWidth = 0.5
limitLine.lineColor = .black
limitLine.valueTextColor = .black
chartView.xAxis.addLimitLine(limitLine)

How do I draw a smooth line chart with ios-charts?

I'm using ios-charts Charts to draw a line chart. I'd like to draw a point every 10 min for a 24h period but my x-axis labels needs to show labels every 4 hours like: 12AM 4 8 12PM 4 8. The problem I run into is Charts complaining that the number of data points does not match the number of x-axes values.
What's the best way do do this type of chart? It can't be that hard. Maybe I just learn to love the warning?
make sure you add enough X values to conform the amount of Y values
use [xAxis setLabelsToSkip:23] (24 xAxis values for 10 min delta in 4 hours)
swift definition: public func setLabelsToSkip(count: Int)
Objective-C: - (void)setLabelsToSkip:(NSInteger)count

XCode iOS UISlider - Custom Scaling Min and Max

I want to have a different scale using a slider for the Min and Max. 0 should be in the middle, but I want to have a scale 0-50 for max and -200-0 for min.
Is that possible? How could I achieve that?
I don't think that this is possible out of the box.
But what you can do is, e.g. setup the slider in a way that for min it has 0 and for max 1000. Now you will have to check in which part of the part, user left the slider. If it's in the lower half, you will have to normalize those values to the desired range, the same for the upper range. The exact middle could be a bit tricky because you will have more points in the slider than in the ranges you are providing, but I guess with some fiddling around you can do this. :)
Hope that helped :)
I believe this is quite possible.
Here is my idea of how you can do it
Take a slider with values -200 to 200
For values > 0. Divide value by 4. (i.e. 200 / 4 = 50)
This will make your positive range from 0 to 50 but negative range from -200 to 0
Similarly while setting value to slider in positive manner you can multiply it by 4.

How to set min and max values for an axis?

I have some data that can have values in the range (0..100). Highcharts will sometimes label the axis from -10 to 110, which looks odd.
How can I prevent this? I can set a fixed min and max value for the axis, but if the current values happen to be between e.g. (50..60), I'd rather let Highcharts zoom in on the axis accordingly. Just don't want Highcharts to ever show anything outside of (0..100).
I could of course determine the appropriate min and max values myself every time I load data, but was hoping there would be some kind of minMin and maxMax setting?
So it looks like this isn't possible; opened a feature request.
Nowadays highcharts has floor and ceiling options for this use case.

Resources