0

I have this bar chart, it has some formatting issues:

bar chart

I'd like to address these:

  • there's strange numbers inside the bars. They could disappear, that would be quite happy.
  • there's also strange, but different numbers above the bars. These could be the actual number.
  • the chart label "recent Apps Data" could look more primary (bigger, bold-italic for example)
  • the dates in the x-axis are .. kinda close. Not sure how to handle that one.

here's how I'm drawing these:

func setBarChart (data: [(String,[Double])], label: String, xLabels: [String]) {
    var entries: [BarChartDataEntry] = []
    for (index, tuple) in data.enumerated() {
        entries.append(BarChartDataEntry(x: Double(index), yValues: tuple.1))
    }

    let set = BarChartDataSet(values: entries, label: DataViewController.constants.labelDate)

    set.setColor(UIColor.orange)

    let data = BarChartData(dataSets: [set])
    barChart.data = data

    barChart.chartDescription?.text = label
    barChart.xAxis.valueFormatter = IndexAxisValueFormatter(values: xLabels)
    barChart.xAxis.granularity = 1

    let legendEntry = LegendEntry()
    legendEntry.formColor = UIColor.orange
    legendEntry.label = "mean performance"

    barChart.legend.setCustom(entries: [legendEntry]);

    barChart.notifyDataSetChanged()
}
roberto tomás
  • 4,435
  • 5
  • 42
  • 71

1 Answers1

1

I do not know the answer to your first three questions, however, I had a similar problem to the one you describe in your fourth question. I discovered two options to overcome the problem of overlaying labels:

  1. You could show labels' texts in two lines by adding \n in the middle of the string (for example, "2018\n07-23"). This would reduce the width of the label and thus they would not cover each other.
  2. The second option could be to reduce the amount of bars shown in the chart. You could achieve this by using setVisibleXRangeMaximum (more on this here).

Good luck!

Tomas
  • 61
  • 1
  • 7