Search code examples
core-plot

Setting xAxis/yAxis hidden property messes up coreplot graph completely


I followed this post Core plot: How to hide the plot, axis and labels? to hide x/y axis. Using the hidden property messes up the plots and shows graph with default x/y axis range (0 to -1)

CPTXYAxisSet *axistSet =(CPTXYAxisSet *)self.graph.axisSet;
axistSet.xAxis.hidden = YES;
axistSet.yAxis.hidden = YES;
axistSet.xAxis.labelingPolicy = CPTAxisLabelingPolicyNone;
axistSet.yAxis.labelingPolicy = CPTAxisLabelingPolicyNone;

Through try and error, the following code achieved what I want: hide the x and y axis while the plots shows correct value.

CPTXYAxisSet *axistSet =(CPTXYAxisSet *)self.graph.axisSet;
axistSet.xAxis.labelingPolicy = CPTAxisLabelingPolicyNone;
axistSet.yAxis.labelingPolicy = CPTAxisLabelingPolicyNone;
axistSet.xAxis.axisLineStyle = nil;
axistSet.yAxis.axisLineStyle = nil;

What is the correct way to hide x and y Axis?


Solution

  • If the graph will never need axes, the best way to remove all of them (e.g., for a pie chart) is to set the axisSet to nil:

    self.graph.axisSet = nil;
    

    If hiding the axes is a temporary operation, set the line styles to nil to hide them.