Setomidor
Setomidor

Reputation: 954

Core plot: How to hide the plot, axis and labels?

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.

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

Upvotes: 8

Views: 5463

Answers (3)

Dan
Dan

Reputation: 1739

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;

Upvotes: 6

storoj
storoj

Reputation: 1867

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;
}

Upvotes: 5

Eric Skroch
Eric Skroch

Reputation: 27381

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.

Upvotes: 6

Related Questions