iOS CorePlot: wrong bar plotting positioning - core-plot

I have a graph created with CorePlot. The user can switch between scatter chart:
and bar chart:
As you can see in the bar chart case the graph gets moved on the right till the point the second bar is not visible anymore. This does't happen when more than 5 elements get displayed:
it looks like the automatic positioning places wrongly some padding but I'm not sure how to avoid this problem.
Any idea?

I think I've found a possible solution, extending the plot space X-axis range in order to include all the elements and leaving a small margin on the right:
// X-Axis spacing
plotSpace.xRange = [CPTPlotRange
plotRangeWithLocation:CPTDecimalFromFloat(0.0)
length:CPTDecimalFromFloat([graphData count] - 0.7)];
I will wait to set this as optimal solution, just in case somebody comes with something better.

Related

Core-Plot DataLabel Z-Ordering

I try to add data labels to a bar graph in Core-Plot (on iOS). The user selects individual plots and then the values are shown.
The main problem is shown in the image, the other plots overdraw the data labels.
Is it possible to have the labels always at the top?
As the user sets the ordering of the bars, I cannot reorder the bars. (Also if I did, the user experience would be terrible as the whole graph appearance would change on selection.)
Other possibility: Can I reorder the plots for Z-ordering but have the positions remain unchanged?
Any other ideas? I also tried CPTPlotSpaceAnnotations, but I cannot align them on the bar precise enough (see the "1037" label at the year (x-axis) 1980).
I came up with a solution by myself: I just remove the plot and add it back. In that way the plot is raised in the z-Hierarchy.
[self.graph removePlot:plot];
[self.graph addPlot:plot];

Core Plot horizontal bar chart on negative y-axis

I have a requirement to draw Core Plot horizontal bar chart with everything on the negative y-axis. I.e. the first index should appear at -1, like below:
I have figured out how to draw horizontal Bar Chart. But figuring out how to draw them in an "inverted" manner (to let user scroll downward with the tallest bar on top). My thought:
1) Convert the Y-index to negative
2) offset the Y-axis to the top of the graph instead of bottom
Is there any better way to do it?
I have found a historical article that's similar to my request (core-plot iOS reversed Y axis).
I have got what I needed after using this:
CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-yMax-1) length:CPTDecimalFromFloat(yMax)
P.S. you need to add the -1 to the Location parameter (-yMax-1) otherwise the horizontal bar at index 0 will not be shown clearly.

Highcharts highstocks - candlestick graph has last value partially cut

In a candlestick graph i am building, the latest bar is cut-off partially such that even the bar is not visible. Thus it's difficult to judge the high and low by seeing the bar.
I'm unable to post a pic now but it's like the last rectangle being cut in half.
I'm tried a lot of options in the api but can't figure out why this is not showing correctly. The chart margin and axis offset options havent' helped. Is there a way i can set the series margin from the plot area so that it displays right.
For this problem, the best solution is to insert a dummy series which should be hidden from every aspect of the chart. So try this, insert a dummy series from the last point of the data series to some extra buffer(as per need). Then remove this series from the chart by explicitly removing it from the legends (using showinlegend),chart(setting linewidth to 0) and from tooltip by having a check in formatter. Hope this solves your problem.
I had the same problem and couldn't figure it out, because no matter how I changed the xAxis.maxPadding or changed the xAxis.max, it would always cut off the last candlestick when I clicked on the range selector.
To solve it, (hack) I just added an extra data point in my series and set it 1 day past the last day and set all values to null.
Without any code or a pic, it's hard to tell the problem, but it sounds like you need to use the max padding option. http://api.highcharts.com/highcharts#xAxis.maxPadding. You may also want to look at endOnTick as well as whether you are setting max on the axis.

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

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!

Shinobi Charts bar graph Customising

I'm using Shinobi Controls Charts to do this project and i'm having some trouble to find ou how to customise my chart to look as close as possible to this:
Here is what i have so far:
The labels at the bottom are the ones that are represented as [name] in the first chart.
The colores of the bars are ok i know how to change them. My problem resides on the labels on the top of each bar and the grid and background grid.
1) How can i remove the grid and change the graph color to transparant? chart.xAxis.style.gridStripeStyle.showGridStripes = NO; does not remove the grid.
2) The radial series had a callback where i could change the labels position, but after taking a look at all the documentation that comes with the demo i can't find anything to change the position of the axis's labels for a bar graph and add more complexity like an image and 2 or 3 labels to it. Also those boxes have to move along with bars.
Does anyone know how to do this 2 topics?
Thank you in advance for any given help.
EDIT :
I've been able to remove the axis with
axis.style.gridStripeStyle.showGridStripes = NO; // removes the main bar
axis.style.majorGridLineStyle.showMajorGridLines = NO; // removes the grid bars
Regarding your second point, use
- (void)sChart:(ShinobiChart *)chart alterTickMark:(SChartTickMark *)tickMark
beforeAddingToAxis:(SChartAxis *)axis
Regarding your first point use
chart.axis.style.majorGridLineStyle.showMajorGridLines = NO

Resources