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

3

8

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.

Tip answered 27/6, 2012 at 11:56 Comment(3)
Try setting graph.axisSet = nil;Ailey
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 :)Tip
Yep, it sure is a work-around :)Ailey
S
5

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;
}
Superstar answered 25/4, 2013 at 19:49 Comment(1)
This doesn't work in the latest version of CorePlot.Rivas
F
6

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.

Fillet answered 8/7, 2012 at 20:52 Comment(0)
E
6

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;
Elvinaelvira answered 23/5, 2014 at 20:22 Comment(3)
It's best to add some explanation with the code you provide for an answer.Preclinical
Thanks Ollie; I added a little explanation.Elvinaelvira
This removes the gridlines when the labelingPolicy is set to .noneRivas
S
5

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;
}
Superstar answered 25/4, 2013 at 19:49 Comment(1)
This doesn't work in the latest version of CorePlot.Rivas

© 2022 - 2024 — McMap. All rights reserved.