How to set the bar width to a fixed value in Shinobi Charts? - ios

I am trying to get used to Shinobi charts developed for iOS. I've downloaded trial version on same and trying to plot some sample charts using it. The charts look pretty good in demo apps. But one thing I noticed that while using class SChartColumnSeries to plot bar chart, the width of the bars is adjusted according to the frame available to plot the chart. I want it to be fixed (say 20 pixels) regardless of number of bars present and if the width required is more than what is assigned (while assigning frame to the chart) then only some part of the chart will be visible and user can scroll the chart to view remaining bars (This is possible in Core Plot). How can I achieve this using Shinobi charts?

This is possible with Shinobi, but it's not a simple case of setting a fixed width property I'm afraid. I've just tried to do this though and its isn't too complicated!
My advice would be to set up the chart like this:
chart = [[ShinobiChart alloc] initWithFrame:self.view.bounds];
[chart setAutoresizingMask:UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];
[chart setDatasource:d];
[chart setXAxis:[SChartNumberAxis new]];
[chart setYAxis:[SChartNumberAxis new]];
[[chart xAxis] setEnableGesturePanning:YES];
[[chart xAxis] setEnableGestureZooming:NO];
[chart.xAxis setDefaultRange:[[SChartNumberRange alloc] initWithMinimum:#5 andMaximum:#10]];
The most important part is the last 3 lines. By turning zooming off you allow your charts to have a fixed zoom level, meaning the bars stay the same width. You can turn the panning on to allow users to scroll to see different bars.
The last line sets the default range. Here, i've just set it to values between 5 and 10. That means that the chart displays values between 5 and 10 along the x-axis.
By doing the above, this means that your columns will have a fixed width! You might have to do some tweaking and / or calculation depending on how many data points you have, in order to find out what you have to set your default range to. If they are variable for example, you will need to take into account the number of data points, the padding between the columns and inter column padding and the number of pixels you have available).
I realise this is quite a simplified answer but it should give you a good starting point!

Related

Increase gap between two point labels in line chart

I have integrated a line chart in my project using Charts library and have been using it for a while now. It was working fine with few data points, however as the number of data have been increased since then the point labels (x-axis) are overlapping with each other. Is there a way to display the data-point labels without getting overlapped?
you can solve this issue using labelCount property. also, you can set using setLabelCount property, I hope this helps you.
xAxis.labelCount = 5
xAxis.setLabelCount(5, force: true)
See this post for more info: https://github.com/danielgindi/Charts/issues/1969
I was not able to find how to increase the gap between two labels on x-axis (top) however I have managed to improve the issue a little by displaying them vertically so that they are at-least visible on chart.
lineChartView.xAxis.labelRotationAngle = 270

How Do I Keep Bar Width the Same Across Multiple Charts?

Suppose I want to create two charts with horizontal bars. The names of the objects are listed on the y-axis and the horizontal bars represents some quantity. The first chart has 100 items and the second chart has 5 items.
When I create the charts the horizontal bars have different widths. I'd like the bars to be the same width across all of my charts.
I know I can try different values for the height parameter to the AddShape function. But that seems time-consuming and unreliable since the number of items can change. I'd like to do something like:
Chart.BarWidth = 10
The "thickness" of each bar will be primarily determined by the number of data points that need to be plotted. The more data points to plot, the thinner the bars will be. There are some options to further tweak them, such as IChartGroup.GapWidth, and you're welcome to try to adjust this so that both charts match. But I suspect that it will be very difficult to do this reliably, particularly if the number of plotted points is expected to change over time.
To maintain the same bar thickness for multiple charts, I think your best option will be to ensure both charts' series refer to the same size range. So if your first chart refers to 100 cells, have your second chart refer to 100 cells, even if only 5 are populated with values. The empty cells should not plot but will still take up space and therefore maintain consistent bar thicknesses between your two charts.

Highcharts: how to optimize auto-scaling so that columns make better use of the available height

Highcharts columns sometimes don't make proper use of the available height, in some cases leaving nearly the upper half of a chart empty. After fiddling with the official example charts I noticed that the y-axis max extreme (internally) seems to be dependent on the chart's container height.
For example, the Highcharts example for stacked column chart:
The original example (container height of 400px) has a max of 12.5 for the y-axis with the largest columns having a value of 11. ~90% of the chart height are used.
When modifying the height to 300px, y-axis max changes to 15, so that only ~75% of the height is used.
When modifying the height to 200px, y-axis max changes to 20, only ~55% of the height being used.
Is there a way to improve this behavior without programmatically setting the axis extremes whenever the displayed data changes? You might argue that applying such a small height to a column chart is a weird thing to do, but this is just an example, I have seen similar behavior with larger charts (having other data).
This is related with fact, that defaulty highcharts has enabled maxPadding. Set that parameter as 0 to fillout area more efficient.
yAxis: {
maxPadding:0
}
The example charts could be fixed with Sebastian's answer. After applying the change to my own chart, I noticed another problem that screwed up the scale even more, but was not part of this question - adding this as another answer, just for the sake of completeness.
My chart consisted of combined column/line chart with a 2nd y-axis. Depending on its values, the line chart series had strange effects on the scale of the columns (even if the line chart series was empty). Doing some more research I found this SO answer pointing me to Highcharts' alignTicks option, setting it to false resolved the issue.

Scrollable Line Chart

Am trying to use the ios-charts library based off the MPAndroidCharts; however am having some trouble getting a scrollable graph to work.
By scrollable I mean that I try to show only a portion of the data of the line and that you can scroll horizontally to see more results. E.g I have 30 results and I only show 10 at a time and then scroll horizontally to see more.
Have come up with an approximation by using the method
[self.containerView setVisibleXRangeWithMinXRange:24.0f maxXRange:24.0f];
However this seems to make the scrolling kind of jittery as it keeps on redrawing.
Am looking for an ios-charts example and clarification on methods to see whether I am on the right track or not.
Similar to your question:
https://github.com/danielgindi/ios-charts/issues/267
Quote:
I was able to achieve this after playing with it a bit. It is actually pretty straight forward.
chart.data = data; // This is the MAIN reason, data for the chart has to be set first before the next 2 steps otherwise they will just get ignored like nothing has been set.
// set the max x data point to 10, which is what i wanted showing only 10 data points for the line or bar chart, from 100 data points.
[chart setVisibleXRangeMaximum:10];
// move the chart view to 90 index of X, which is the last 10 entries I want to see. and it works as expected.
[chart moveViewToX:90];
Other helpful ones:
https://github.com/danielgindi/ios-charts/issues/226
https://github.com/danielgindi/ios-charts/issues/258

Core Plot: How do you centre the axis labels beneath bars / horizontally offset them?

I am making a column chart in Core Plot, and I want the x-labels to appear beneath the columns, rather than on the left and right. Having trouble finding solutions through searches; either outdated or not related. Feel like plenty of people have had this problem before, I'm just using the wrong keywords.
Screenshot of how it looks right now:
Thanks
The bars are centered at the bar location returned from the datasource, plus or minus any barOffset. For a stacked plot like this, use the default barOffset of zero (0) and make sure the bar locations match the tick locations on the axis.

Resources