8
votes

I have a graph with Y and X axises drawn on the default plot space along with the primary plot, and then I have separate plot spaces for auxiliary plots each with their own Y-axes (the X-axis is the same for all plots).

I'm implementing buttons to switch the auxiliary plots on and off and I would like this to include basically the whole plot space (plot, custom y-axis, and labels of the custom y-axis). There doesn't seem to be any 'hidden' property for the plot space, and all-tough the plot and the axis both have 'hidden' properties, setting these to 'YES' leaves the axis-labels visible.

  • What is the best way to completely hide the contents of a plot space without causing more redrawing than necessary?

I guess one way could be to remove the plot space and plot from the graph completely, but this feels unintuitive.

3
Try setting graph.axisSet = nil; - Vidya Murthy
That would remove all axises in the graph, I would only like to hide the axis/axes associated with the auxiliary plots. I guess one solution is to keep references to all axises and re-configuring the axisSet of the graph as you suggest (omitting the axes that should be hidden), but it feels like a hack :) - Setomidor
Yep, it sure is a work-around :) - Vidya Murthy

3 Answers

6
votes

Set hidden to YES on the axis you want to hide. If you're using custom labels (labeling policy CPTAxisLabelingPolicyNone), just set the axisLabels to nil. Set new labels when you want them to reappear. For the other labeling policies, set the labelFormatter to nil to hide the labels and assign a valid formatter when you want them visible.

6
votes

You can set all axes as hidden at the axisSet level, and you can also hide the labels by assigning a labeling policy of CPTAxisLabelingPolicyNone to the axes. This solution worked well for me:

CPTXYAxisSet *axisSet = (CPTXYAxisSet *) self.graphHostingView.hostedGraph.axisSet;
axisSet.hidden = YES;

CPTAxis *y = axisSet.yAxis;
y.labelingPolicy = CPTAxisLabelingPolicyNone;

CPTXYAxis *x = axisSet.xAxis;
x.labelingPolicy = CPTAxisLabelingPolicyNone;
5
votes

you may also set all labels hidden

CPTAxis *axis = someAxis;
hidden = YES;

axis.hidden = hidden;
for (CPTAxisLabel *axisLabel in axis.axisLabels) {
    axisLabel.contentLayer.hidden = hidden;
}