-
-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Is there a way to use Line Chart with custom xAxis? #3579
Comments
Strong +1 for this, my use case is displaying time series data, where x values are of |
Does it appear as strings later on the Dax is? I want to later test it for
dog properties such as life span etc on the x axis
…On Wed, Jul 25, 2018 at 8:30 AM Max Desiatov ***@***.***> wrote:
Strong +1 for this, my use case is displaying time series data, where x
values are of NSTimeInterval type, but should be formatted as dates on
the x axis.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3579 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AlXR6lcVdZn0mBM0Sa1eLaCzyJzqVJ8Vks5uKI8cgaJpZM4VgQ2Q>
.
|
look at #3069 |
It only appears as a formatted |
Does this mean that I won't be able to insert strings on the x-axis? Would it be only possible for barographs? I want to use a line graph but with categories in strings on the x-axis. |
After a quick investigation, looks like import Charts
import UIKit
final class DateValueFormatter: IAxisValueFormatter {
func stringForValue(_ value: Double, axis: AxisBase?) -> String {
return formatter.string(from: Date(timeIntervalSinceReferenceDate: value))
}
let formatter: DateFormatter
init(formatter: DateFormatter) {
self.formatter = formatter
}
}
let dataSetSize: CGFloat = 14
final class ViewController: UIViewController {
@IBOutlet weak var chartView: LineChartView!
func refresh() {
// Do any additional setup after loading the view.
let ys1 = Array(1..<10).map { sin(Double($0) / 2.0 / 3.141 * 1.5) }
let ys2 = Array(1..<10).map { cos(Double($0) / 2.0 / 3.141) }
let yse1 = ys1.enumerated().map { ChartDataEntry(x: Double($0), y: $1) }
let yse2 = ys2.enumerated().map { ChartDataEntry(x: Double($0), y: $1) }
let data = LineChartData()
let ds1 = LineChartDataSet(values: yse1, label: "Hello")
ds1.valueFont = .systemFont(ofSize: dataSetSize)
ds1.colors = [.red]
data.addDataSet(ds1)
let ds2 = LineChartDataSet(values: yse2, label: "World")
ds2.valueFont = .systemFont(ofSize: dataSetSize)
ds2.colors = [.blue]
data.addDataSet(ds2)
let f = DateFormatter()
f.dateStyle = .short
chartView.xAxis.valueFormatter = DateValueFormatter(formatter: f)
chartView.data = data
chartView.gridBackgroundColor = .lightGray
chartView.backgroundColor = .white
chartView.chartDescription?.text = "Linechart Demo"
}
override func viewDidLoad() {
super.viewDidLoad()
refresh()
}
} |
it's false
IAxisValueFormatter is obsolete |
@thierryH91200 would you kindly provide any documentation or references that confirm that this protocol is obsolete? In the latest Charts 3.1.1 it's not marked as either obsolete or deprecated and the example code I provided works perfectly well and is able to change X axis labels without a problem. Please have a look at the attached screenshot, which is made from the example code from my comment above. |
it's a mistake I was too fast
|
@katisari change |
Okay that works! But do I have to use date formatter in the class that's inheriting from the IAxisValueFormatter? Am I allowed to change formatter variable to type String? It throws me an error when I try to do that. |
@katisari you don't have to use a date formatter, you can produce whatever string is needed as long as your formatter conforms to |
Seems it's answered by great people, closing. |
I'm trying to create a Line Chart with custom xAxis labels.
I want to put different categories in the axis for such as ["january", "Feb", "March"]. Is there any way to do that for line charts?
The text was updated successfully, but these errors were encountered: