iOS Charts zoom property - ios

I am using iOS charts library and in my application there could be lots of x axis values for my bar chart view but, I need to show few of them. I have tried to do it with barChartView.setVisibleXRangeMaximum(12) though it is causing some weird issues. (Like Bar chart's bar fill all x-axis) Instead of using that function I am trying to use zoom property barChartView.zoom(scaleX: 4, scaleY: 0, x: 0, y: 0) . However, I am not sure how many x axis values come when I draw the chart. In some cases, it's 60,84 or 800. How can I calculate right zoom ratio to accomplish for showing 10-12(any number between them enough for me) x-Axis values?

You might want to use:
barChartView.setVisibleXRange(minXRange: 10.0, maxXRange: 12.0)
instead of:
barChartView.setVisibleXRangeMaximum(12.0)

Related

translation of view based on values on graph y axis in Swift

I want to implement line chart like this image. I have already bar chart implemented which display proper value based on scaling like
barView.transform = CGAffineTransform.init(scaleX: 1, y: self.projectionValue)
Now i want to do same in line chart but using transformation as i can not change height of bar but move to view on specific value so how can i do this?

Swift ios : Implement scroll on Bar chart

Tried to implement scroll on Barchart using scale x to 2 for zoom in. But the issue is the x-axis values are not center-aligned with Bar chart.
Labels count is based on day and month values.
barChartView.xAxis.axisMinimum = 0.0
barChartView.xAxis.axisMaximum = Double(labels.count - 1)
barChartView.setVisibleXRangeMaximum(Double(labels.count)/2)
or
barChartView.zoom(scaleX: 2, scaleY: 0, x: 0, y: 0)
for scroll implemented like,
barChartView.xAxis.setLabelCount(Int(Double(labels.count)/2), force: true)
Please suggest to us the correct approach to avoid miss align of x-axis values with the bar chart.
From your code, I assume your expected behaviour is that the chart
shows at most half of all available bars
allows the user to zoom indefinitly (minimum = 0)
allows the user to scroll (left/right)
If this is the case, you would apply the following code:
barChartView.xAxis.axisMinimum = 0.0
barChartView.xAxis.axisMaximum = Double(labels.count - 1)
barChartView.setVisibleXRangeMaximum(Double(labels.count)/2)
barChartView.xAxis.setLabelCount(Int(Double(labels.count)/2), force: false)
.zoomshould be avoided since it sets multiple unwanted values (scaleY, x, y) and hence adds unwanted features when scrolling.
It is important to set the force flag to false. This is the parameter that caused your miss alignment as described in the documentation:
https://weeklycoding.com/mpandroidchart-documentation/axis-general/
setLabelCount(int count, boolean force): Sets the number of labels for the y-axis. Be aware that this number is not fixed (if force == false) and can only be approximated. If force is enabled (true), then the exact specified label-count is drawn – this can lead to uneven numbers on the axis.

How to have fixed points in one screen using and then swipe to get to the next page using ios-charts?

I am using Swift trying to generate chart using the ios-charts api and having trouble containing same amount of point in the scene now. The chart is beautiful when having 5 points, like this picture with 5 points, however, when it comes to more points, it is really messy: picture with more points. So is there a way for me to keep just 5 points every scene and let the user swipe to get to another page? Thanks!
Yes, you can limit visible X range like so..
lineChartView.setVisibleXRange(minXRange: 5, maxXRange: 5);
This will make only 5 points visible at a time, and will allow the user to scroll left or right for more.
As mentioned above - you can set same values for min and max in:
func setVisibleXRange(minXRange minXRange: CGFloat, maxXRange: CGFloat)
If you want your chart to be able to zoom (probably you do), then you need to change these values again in delegate methods, setting different numbers, so you can zoom chart e.g.
func chartScaled(chartView: ChartViewBase, scaleX: CGFloat, scaleY: CGFloat) {
self.chartView.setVisibleXRange(minXRange: 1, maxXRange: 10)
}

How to properly align Font Awesome symbols on Highcharts scatter plots?

Using the Highcharts example posted here how can you ensure that the Font Awesome icons will be positioned exactly in the middle of the data point like the native symbols/markers are? It gets called like this in the data series and uses the "plugin" that is found in that same Fiddle:
marker: {
symbol: 'text:\uf183' // fa-male
}
Using that example, if you toggle the series on/off a couple of times or zoom in/out the icons are no longer visually accurate, often displaying above the actual coordinate. In the image below you'd believe that data point had a value >50 based on where the icon is.
Their SVGRenderer example here doesn't seem to be effected.
It looks like problem with re-rendering icons later - height of the marker isn't considered. I suggest to change a bit logic for rendering icon:
var text = symbol.split(':')[1],
svgElem = this.text(text, x, y)
.attr({
translateY: h, // translate marker
translateX: -1
})
.css({
fontFamily: 'FontAwesome',
fontSize: h * 2
});
See demo: http://jsfiddle.net/2A7Zf/29/
If you want to use the markers XL-sized (i.e larger radius) for a custom chart (e.g. a Yes/No prevalence chart using the x and check icons, circle empty for the less prevalent one and circle filled for the more prevalent one and data labels showing counts/%s), then I'd recommend this tweak to center the symbols:
translateX: -w/2 + options.radius/4 - 3

Axis Lables Rotation

Hi I am using HighStock 1.2.4
I do have multiple series and separate yAxis for each series. I am calculating height and topPadding and creating stacked series.
Now, I am facing two problems.
I have used rotation with yAxis to rotate labels but its not rendering correctly.
Example: http://jsfiddle.net/mhardik/uZaWz/9/
I have also used rotation for X Axis labels, but the last series position is getting messed with X Axis Labels.
http://jsfiddle.net/mhardik/uZaWz/10/
1) I'm not sure why it's not rendering correctly, if you want to move a little to the left use x: property for title.
2) First, I think you need to set proper align for xAxis.labels (right). Then make higher chart to make sure you have enough space for a chart.
And jsFiddle: http://jsfiddle.net/Fusher/uZaWz/12/

Resources