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

Swift: Custom Xaxis and Yaxis problem. #1740

Closed
sashalondon opened this issue Oct 28, 2016 · 2 comments
Closed

Swift: Custom Xaxis and Yaxis problem. #1740

sashalondon opened this issue Oct 28, 2016 · 2 comments

Comments

@sashalondon
Copy link

I am using the formatter to format the xAxis for the date and that works well. I have tried to format the yAxis but I get the same information as the xAxis format on the yAxis. How can I differentiate between the two axis in the formatter class?

public func stringForValue(_ value: Double, axis: AxisBase?) -> String {
    daysChosen = AnalysisDataStruct.segmentTimeChosen
    months = today.chartStringArrayOfDateForPrevious(numberOfDays: daysChosen).reversed()
    return months[Int(value)]
  }


Public func stringForYAxisTrueOfFalseValue(_ value: Double, axis: AxisBase?) -> String {
    if value == 0 {
      return "Not Present"
    } else {
      return "Present"
    }
  }

In the ChartViewController

  _ = Array(0...(numberOfReadings - 1)).map { x in return self.formato.stringForValue(Double(x), axis: self.xaxis) }
 self.xaxis.valueFormatter = self.formato

    _ = ys2.enumerated().map { x, y in return self.formato.stringForYAxisTrueOfFalseValue(Double(x), axis: self.yaxis) }
 self.lineChart2.leftAxis.valueFormatter = self.yaxis.valueFormatter
@sashalondon sashalondon changed the title Swift: Custom Xaxis and Yaxis Swift: Custom Xaxis and Yaxis problem. Oct 28, 2016
@liuxuan30
Copy link
Member

Please explain what's the problem and better having a screenshot. I barely understand..

@danielgindi
Copy link
Collaborator

You can test for the kind of axis, or you can have two different formatter classes, which is the right way to do this.
If you're lazy and don't want to create another formatter class, you can initialize a Default formatter with a block, as mentioned in the release notes of 3.0.0.

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

No branches or pull requests

3 participants