Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: optional axis rendering? #206

Closed
NachoSoto opened this issue Jan 11, 2017 · 1 comment
Closed

Question: optional axis rendering? #206

NachoSoto opened this issue Jan 11, 2017 · 1 comment
Labels

Comments

@NachoSoto
Copy link
Contributor

Is there a way to render a chart with just one axis? I see ChartCoordsSpaceLeftBottomSingleAxis, ChartCoordsSpaceLeftTopSingleAxis, ChartCoordsSpaceRightBottomSingleAxis, and ChartCoordsSpaceRightTopSingleAxis, but no version with no vertical axis.

It looks like ChartBarsLayer requires both axis. Would it be possible to make them optional?

@ivnsch
Copy link
Owner

ivnsch commented Jan 11, 2017

You always need the axis, to define the coordinate space, but you can simply not pass it to the chart layers. Then it will not be displayed:

let chart = Chart(
    frame: chartFrame,
    layers: [
        coordsSpace.xAxis,
//        coordsSpace.yAxis,
    ]
)

To remove the reserved space you have to set related spacing settings to 0 and don't pass any text to the axis. In detail:

Set labelsToAxisSpacingY, spacingBetweenAxesY, labelsSpacing and axisTitleLabelsToLabelsSpacing to 0. (Just noticed that the later should be specific to each axis, or at least not be used when you don't pass a title / in fact all these settings should be conditional - right now this affects also the other axes, though it looks ok. You also can change the value of leading to compensate for this).

Don't pass an axis title:
let yModel = ChartAxisModel(axisValues: yValues, axisTitleLabels: [])

Finally, use axis labels that don't display text (otherwise the max label width will be reserved). For this you can use this custom class:

class ChartAxisValueInvisible: ChartAxisValue {
    override var labels: [ChartAxisLabel] {
        return []
    }
}

Since you are not displaying the axis values you only have to pass the first and last value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants