X-axis action strange - Charts iOS - 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

Related

simple xAxis granularity setting in iOS Charts framework

i have been experimenting with the charts framework and things seems to be running as expected except the behavior of the xAxis.granularity setting.
barChartView.xAxis.valueFormatter = IndexAxisValueFormatter(values: ["A","B","C","D","E","F","G","H","I","J","K","L"])
barChartView.xAxis.granularityEnabled = true
barChartView.xAxis.granularity = 1
when i set granularity to 2 or above, i get the expected behavior of xAxis label spread out by the value i specified. (the 3 images are for a granularity of 2,3,4)
but when i set granularity = 1 expecting a label under every barchart, i get this
what am i missing ? or is there another setting to force a label at every point ?
thanks
Try setting
setLabelCount(12, force: true) // replace 12 with your data.count

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 to set the label count for X axis in LineChartView?

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.

iOS-charts radar chart removing labels and filling the web with color

Probably a very basic question.
I am using iOS-charts and am working with a radar chart.
I am struggling to figure out how to remove the labels from the graph and I am really struggling to FILL the web. I can change the outer lines but I want to fill the web/data in a specific colour.
any help would be much appreciated.
Kind regards
Wayne
So, there are two types of labels on a radar chart, the axis label that shows you the list of possible values on the chart from min to max and the labels that correspond to each point on your graph.
REMOVING AXIS LABELS
Grab either the x or y axis on your radar chart view and set drawLabelsEnabled to false depending on the axis of the labels that you wish to hide
let yAxis = radarChartView.yAxis
let xAxis = radarChartView.xAxis
yAxis.drawLabelsEnabled = false
xAxis.drawLabelsEnabled = false
REMOVING LABELS FOR VALUE OF EACH POINT
Go to the location that you create your RadarChartDataSet
Before using it to create your RadarChartData, set the drawValuesEnabled property to false
let radarChartDataSet = RadarChartDataSet(yVals: dataEntries, label: "label")
radarChartDataSet.drawValuesEnabled = false
Also, here's a link to the Charts documentation page which can also be helpful (although it is not fully filled-in): http://cocoadocs.org/docsets/Charts/2.0.9/index.html

setting yAxis in iOS-charts swift iOS 8

I'm learning ios-charts and I was wondering how to manipulare the yAxis since there is no method related to that. On the contrary xAxis can be customized.
A small example, by default I have two set of labels for the yAxis as the figure shows.
I managed to move the xAxis labels using
lineChartView.xAxis.labelPosition = .Bottom
but there is no such thing for the yAxis.
Is it possible to leave just the labels on the left clearing the labels on the right?
use rightAxis.drawLabelsEnabled = false or even rightAxis.enabled = false.
The xAxis is rendered by xIndex, which means the distance between each data point on xAxis is equal. But yAxis is rendered by the data value and the yaxis range.
So be careful, when you are setting the dataSet, you got a chance to set the axis dependency, like dataSet.axisDependency = axisDependencyRight. Then it will use rightAxis to render your line chart, not left axis. By default, it is axisDependencyLeft
You can choose which yAxis you would like to have, and just disable the other one. rightAxis.drawLabelsEnabled = false just don't render the label, but still calculated and rendererd. Watch out for this.
I think that the only way to do it is the following
let yaxis = lineChartView.getAxis(ChartYAxis.AxisDependency.Right)
yaxis.drawLabelsEnabled = false

Resources