J_A_F_Casillas
J_A_F_Casillas

Reputation: 79

How to set name on X axis Using charts on Swift 4?

This is my inquiry (edited):

I try to plot a monthly graphic using Charts, but I face some difficulties to put the names of the months on the X axis. My default value is like in the next image: default value

And after using the most upvoted answer from here, I got this

So after investing some hours with futile results I'd like to ask you if you know how to get a plot similar to this one, please. So to summarize:

  1. Put the names of the months on the x axis (Vertical, not horizontal as in the figure)
  2. Plot the months' names on the base of the graphic, not on the top as seen on the default value

Thanks in advance. If you need some of my code, I can share it with you.

Kind regards.

Upvotes: 1

Views: 845

Answers (1)

J_A_F_Casillas
J_A_F_Casillas

Reputation: 79

After playing around and with a better research, this is the answer to my questions:

//Give the value of the months to the x axis
    barChart.xAxis.valueFormatter = IndexAxisValueFormatter(values:months)
    barChart.xAxis.granularity = 1

//Position of the x axis, rotation of the labels on the x axis and show all the names of the months consecutively
    barChart.xAxis.labelPosition = XAxis.LabelPosition.bottom
    barChart.xAxis.labelRotationAngle = -90.0
    barChart.xAxis.setLabelCount(counter, force: false)

Upvotes: 1

Related Questions