Core plot - disable scaling and scrolling in the y direction, not x - iphone

I'm working on a graph displaying dates on the x-axis, and percent on the y-axis (1-100). I have got the graph to show kind of the way I like, but I want to disable the ability to scroll and scale the graph in y-direction, so the values 1-100 always is displayed at the same scale. However, I cannot disable user interaction completely, as I want the user to be able to scroll (and perhaps scale) in the x-direction as the number of dates gets bigger, and touch the nodes to display values.
I was able to to this in s7graphview, which I was using before, but haven't been able to get this to work with iOS 5. Also, the smooth scrolling I got from the scrollView in s7 had been fine to have in Core Plot :)

//for stop vertical scrolling
-(CGPoint)plotSpace:(CPTPlotSpace *)space willDisplaceBy:(CGPoint)displacement{
return CGPointMake(displacement.x,0);}
-(CPTPlotRange *)plotSpace:(CPTPlotSpace *)space willChangePlotRangeTo:(CPTPlotRange *)newRange forCoordinate:(CPTCoordinate)coordinate{
if (coordinate == CPTCoordinateY) {
newRange = ((CPTXYPlotSpace*)space).yRange;
}
return newRange;}

The easiest way to do that is to set the globalYRange of the plot space to the same range as the yRange. If you need to expand the yRange later, remember to remove the globalYRange first (set it to nil).
To get more control, you can use a plot space delegate. Implement this method:
-(CPTPlotRange *)plotSpace:(CPTPlotSpace *)space
willChangePlotRangeTo:(CPTPlotRange *)newRange
forCoordinate:(CPTCoordinate)coordinate;
You can use this method to modify the proposed change to the plot range.

Related

Matlab GUI Scrollbar Available

Does anyone know if I can make a horizontal and vertical scroll bar in a MATLAB GUI (not a list box)? Depending on the resolution of a computer it may or may not show all of the figure so I need to be able to scroll (horizontally in my case). How to do that?
This will create a figure with a horizontal scrollbar:
figure
plot(1:3);
b = uicontrol('Parent',gcf,...
'Style','slider',...
'Units','Normalize',...
'Position',[0,0,1,0.05],...
'min',0, 'max',1,...
'Value', 0);
However, if I were you, I would rather make sure the figure fits the screen and allow the user to zoom. Having a graph larger than screensize deprives the user from observing the entire graph at once.
You could
a) let matlab choose default figure size of the figure. Then the user can fullscreen if desired, or b)
screensize = get(groot,'Screensize');
figure('Position',screensize)
I hope this helps.

ios-charts - problems using autoScaleMinMaxEnabled

I try to auto scale the y-axis for an LineChart. If I set the option autoScaleMinMaxEnabled, followed by an notifyDataSetChanged no auto scale occurs.
Also toggeling autoScaleMinMaxEnabled in ChartsDemo seems not to work. Is there a special trick?
Many thanks! - Tino
The "trick" is that min/max of the Y-axis is determined dynamically, during scrolling, depending on the y-values that are contained in the visible x-range.
If you want to see it working in the demo, then zoom in, enable autoScaleMinMaxEnabled, and then scroll to the right. Watch the Y-axis.

Stop Android Graph View from rounding the x-axis

I'm using graph view in my project and got it working just fine. However I don't like the x-axis values. The values I'm passing are 0,0.5,1,1.5,2,2.5...all the way to 23.5. I would like the graph to show every x-axis value on the grid and not rounded values of 0,3.4,6.9,10.3, 13.7 etc. Is there a way to force it to not round and use the x values provided?
the labels are have fix positions and shows the exact value at this point. It seems, that you want to have the another count of labels or other positions. In the current GraphView version you can set set count of labels. When you configure it in the correct way, you should see labels in 0.5-steps.
Have a look at GraphViewStyle#setNumHorizontalLabels

How to Create Customized Time Bar in iPhone?

I need to create a time bar like the image attached.The blue lines are the dates indicating some actions.The big Red Arrow mark is used to slide for selecting any of the blue line. At background the bar is divided into years.The small red circles are to indicate the years.
Any idea ,how do i start?
Thanks
If the blue bars don't move a lot, and you don't need to resize this view very often (which is usually the case on an iPhone), then I'd recommend subclassing UIControl (or UIView) and implement it yourself.
Have an NSArray property storing NSDate objects and methods like addDate:, removeDate:, removeDateAtIndex: to change it's content from an other object (like your view controller). In these methods you add or remove the passed date and call [self setNeedsDisplay]; to redraw the lines.
You will need a few methods to calculate the position (in pixels) of a date on the slider and to calculate the date at a specific coordinate. This should be easy to to (basic linear interpolation).
And assuming that the red slider is only able to point to blue lines (but not between them) add a NSDate pointer variable to the currently selected date. In the
In the drawRect: method, you need to draw all the lines using CoreGraphics functions. Look up the documentation if you need help with this. Apple has some great sample apps too.
To show the red slider, you could either add a custom UIImageView, with a UIPanGestureRecognizer and make sure it only moves vertically in the gesture handler. Or it might be possible to add a UISlider without track images (I'm not 100% sure about that). In either case, you need to adjust the slider's position once the user let's go and make it jump to the nearest blue line.
A rough idea,
1. Get the length of the entire TimeBar.Let it be t.
2. Divide by x=numberofYears*365.let it be t_eachday_pos=t/x
3. get the position of each day,calculate its offset as daycount*t_eachday_pos;
4. Add your blueLine as a customButton.
5. To do some action, pass the x daynumber(eg. day 245 of year 2 etc.)
Try this, I have used the same thing in one of my app, and it is working

iPhone Core plot: how to zoom in this following example?

I am not talking about just resize the image,
I want to zoom in the price, then people focus on that price.
I want to do a resize action, then data will reload the specify area of the chart.
Similar as this application:
http://itunes.apple.com/us/app/chart-tool/id366727994?mt=8
You can zoom in by adjusting the plot ranges on the plot space. Reduce the length of the range to zoom in and increase it to zoom out. No need to reload the data unless you want to add more detail (== more data points) at the higher zoom level.