Volume overlay on top of price chart

11 views
Skip to first unread message

Eric

unread,
Oct 19, 2009, 1:52:55 PM10/19/09
to coreplot-discuss
Hello,

I am attempting to add a volume overlay plot on top of a financial
price chart. I've created a separate plot space for the volume plot
(which is a bar chart) and added it to the same graph that contains a
plot space for the price chart (which is a scatter plot).

I noticed that the volume plot bar chart resets its range location to
0 (probably as part of a normalization process). What I really need
is for the volume plot x-scale to remain the same as the main chart's
x-scale. The following code seems to work (in that it forces the
volume bar chart to _initially_ have the same xRange). However, after
new points come into the chart (once the historical data loads up),
the volume plot starts scaling down very quick (effectively shrinking)
at a different rate than the main chart. This happens even though I
force volumePlot xRange == mainPlotSpace xRange).

_volumePlot.plotRange = mainPlotSpace.xRange; // this makes sure
volume xRange doesn't normalize to 0
[_volumePlot reloadData];
[_volumePlot.plotSpace scaleToFitPlots:[NSArray
arrayWithObject:_volumePlot]];
((CPXYPlotSpace *)_volumePlot.plotSpace).xRange = p
mainPlotSpace.xRange; // volume must have same time scale as main plot


The doc for CPBarPlot.plotRange says this: "The bars are spaced
evenly throughout the plot range". I think this may be the key to the
problem. I believe the bar plot is re-spacing the existing data
evenly with the new points that come in, instead of plotting the new
points at the point on the xAxis that is required by the value I set
for CPBarPlotFieldBarLocation. Am I correct here, or is something
else wrong? I summary, I suppose I'm asking how one would go about
"correctly" adding a volume overlay plot on top of a price chart such
that both charts scale with the same x-Axis (time) range?

Thank You,
Eric

Eric

unread,
Oct 19, 2009, 2:32:15 PM10/19/09
to coreplot-discuss

Eric

unread,
Oct 19, 2009, 2:45:54 PM10/19/09
to coreplot-discuss
This workaround seems to work. It is not ideal because it is a
subclass rather than a modification to CPBarPlot itself, but it will
do the trick for those who need it 'now'.


@interface MyBarPlot : CPBarPlot
@property (nonatomic, readwrite, copy) NSArray *barLocations;
@end

@implementation MyBarPlot

@dynamic barLocations; // defined in superclass

- (void)reloadData
{
[super reloadData];
assert(self.dataSource != nil);
CPXYPlotSpace *xyPlotSpace = (CPXYPlotSpace *)self.plotSpace;
NSRange indexRange = [self
recordIndexRangeForPlotRange:xyPlotSpace.xRange];
self.barLocations = [self
numbersFromDataSourceForField:CPBarPlotFieldBarLocation
recordIndexRange:indexRange];
}

@end

Drew McCormack

unread,
Oct 23, 2009, 10:53:44 AM10/23/09
to coreplot...@googlegroups.com
That is correct. It hasn't been implemented yet. Sorry.
The current implementation only does the even spaced variety. Note
that you can set the range of the CPBarPlot to correspond to the
xrange, so things work OK.

Drew

TIK Sathaphorn

unread,
Oct 13, 2016, 7:05:46 AM10/13/16
to coreplot-discuss
I have same problem with you. Would you mind if i'd like to have example code.
I need to display 2 charts in one graph. top and below position 

Eric

unread,
Oct 13, 2016, 7:50:59 AM10/13/16
to coreplot-discuss
This thread is seven years old. The problem described here was fixed a long time ago. There are many examples included with Core Plot in the "examples" folder. Several, like the Stock Plot app and several demos in the Plot Gallery app, include multiple plots in one graph.

Review the example apps and if you still have questions, start a new thread describing what your goal is and what you've tried so far.

Eric
Reply all
Reply to author
Forward
0 new messages