Pass custom data into datetime axis labels formatter - highcharts

It is quite easy to pass custom data into tooltip formatter by simply adding additional property for each series data item.
But I can't seem to find a way to pass property into xAxis.labels.formatter without using global scoped variables.
Currently I need to pass a string which will help me with custom formatting of label in future.
Anyone knows how to do this?

You can define a custom property in labels options object. Actually you can define a property wherever you want, but I assume this place fits the most.
In a formatter callback you can access to it via this.axis.options.labels['customProperty'].
xAxis: {
categories: ['Foo', 'Bar', 'Foobar'],
labels: {
formatter: function () {
return this.value + ' ' + this.axis.options.labels.myString;
},
myString: 'myString'
}
},
Example: http://jsfiddle.net/0o4xe4rb/

Related

Capture Textfield value without hitting return key in SwiftUI [duplicate]

This question already has answers here:
SwiftUI TextField with formatter not working?
(9 answers)
Closed 2 years ago.
Is there a way to capture the value in the TextField without hitting the return key? I have a TextField that I would like to capture the value (years) without hitting the return key.
onEditingChanged is triggered only when the field has focus or left focus
onComit is triggered only when the return key is hit.
The scenario I am looking at is when I enter "5", for example, in the field and hit "Done", I would like to capture the new value not the existing value.
TextField("Number of Years...", value: $years, formatter: integerFormatter, onEditingChanged: { _ in
print("OnEditingChanged: \(years)")
},
onCommit: {
print("\(years)")
})
Firstly, add #State variable 'year':
#State private var year: Int = 0
Secondly, pass Binding to TextField 'text' parameter and use formatter inside, like this:
TextField("Year", text: Binding<String>(
get: { String(year) },
set: {
if let value = NumberFormatter().number(from: $0) {
self.year = value.intValue
print("Year: \(year)")
}
}
))
It will print 'year' value until something else but number will be pressed on the keyboard.
To leave only number input you can set keyboardType to your TextField:
.keyboardType(UIKeyboardType.numberPad)
Edit: Apparently with Formatters the value doesn't just update live. A pattern you could try would be having the text field set a #State String and have .onChange trigger a formatting function ... or have a get/set Binding that runs that function for you.
In this way, any button push to exit the view can pul the live raw String from the user input, as well as set that String to whatever formatted version you want.
If focus change is an issue, you might pick stuff up from: https://www.youtube.com/watch?v=SYBmMugnol0&feature=emb_rel_pause
=============
So, teehee, you might laugh, but you already have it working.
Add
.onChange(of: years) { print($0) }
and you'll see what I mean. The #State property is already delivering you a live feed. If you're using Combine to drive some sort of processing pipeline, you might want to deduplicate and and debounce. Apologies if you're not a beginner and what I just wrote was pedantic.

Angular material dateAdapter does not consider different hours/minutes/seconds as a different date

I'm building a time extension (hours/minutes/seconds) for angular material DatePicker (beause there aren't any good ones out there yet). The problem is when I update the time in the time component I use the DatePickers select method which is the only method to set dates programatically using a Date object.
The problem is Datepickers inner select function does not consider different Hours/Minutes/seconds as a different date, and when supplied with such scenarion it will not update its inner workings.
The following is the select function of Angular Material Datepicker:
MatDatepicker.prototype.select = function (date) {
var oldValue = this._selected;
this._selected = date;
// this will eveluate as false since only hours/minuts/seconds are different and not day/month/year
if (!this._dateAdapter.sameDate(oldValue, this._selected)) {
this._selectedChanged.next(date);
}
};
Inside the sameDate method they use a method called compareDate which check the two dates only by day and month & year:
DateAdapter.prototype.compareDate = function (first, second) {
return this.getYear(first) - this.getYear(second) ||
this.getMonth(first) - this.getMonth(second) ||
this.getDate(first) - this.getDate(second);
};
This means select method will not emit the new date to DatePicker's inner components & parts.
I am using a custom NativeDateAdapter and a custom MatDateFormats but since the above check want emit the new date these mechanism want be reached.
P.S
Everything works ok when the updated date has a different day/year/month including the custom time formating to include the time parameters.
I resolved this by simply re-implementing the base classes compareDate method using the custom NativeDateAdapter.
export class AppDateAdapter extends NativeDateAdapter {
format(date: Date, displayFormat: Object): string {
// format your dates
}
compareDate(first: Date, second: Date) {
// compare first/current date with second/previous date
// you can implement your logic here.
return 1;
}
}

How to set a NSManaged variable?

I have a NSManagedObject class with two relationships: courseAand courseB.
These relationships should be represented in a dynamic variable. How is it possible to change this variable from outside the class?
#objc(Universtity)
public class Universtity: NSManagedObject {
dynamic var name: String {
get {
let name = self.courseA?.name
return name!
}
}
}
For example from within a ViewController like University.name = University.courseB.name ?
I was thinking about a Notifikation, but this seems maybe a little more complicated as it could be.
And if there is no other way, how should I implement the observer inside the University class?
Thank you for every idea.
Looking at your code, you have declared a "computed" or "ready-only" variable. This is a variable whose value comes from another variable or combination of variables.
I can't see your data model, so it's not clear if you have defined a name parameter in the Core Data model. Regardless, if you have the logic is somewhat confused, because the getter you have defined means any value it may hold would be ignored anyway. You would need to define a setter to set self.courseA.name if you want to ensure the value can be written to. You don't need to worry about key-value coding notifications, because they will be triggered by the Core Data Managed Object.
public class Universtity: NSManagedObject {
dynamic var name: String {
get {
let name = self.courseA?.name
return name!
}
set(newValue) {
courseA!.name = newValue
}
}
}
Also the pattern you have used to force unwrap a non-optional value in your getter isn't optimal. I haven't edited this because that is another discussion, but I would suggest asking yourself the question am I sure why I am doing this? for every "?" and "!" you use.

Xcode6 autogetters and autosetters

Xcode6 ios swift
I have created my own class and trying to make an autogetter and autosetter, but i don't really know if it's allowed.
var Birthday:NSDate {
get {return birthday}
set(newValue){birthday = newValue}
}
var BirthYear:Int32 {
get {}
set {}
}
The last part of code triggers error, missing return, so my question is that - Is there any possibility to make getter and setter without making a second variable
Stored properties in swift are backed by hidden instance variables - the property itself is its own getter and setter, unless you implement it as a computed property, in that case you have to provide your own getter and/or setter. So when you write:
var birthday: NSDate
you use it as:
let value = classInstance.birthday
to read its value, and
classInstance.birthday = someDate
to assign a new value. You don't have to do anything special to make that work.
Suggested reading: Properties
Side note: by convention variables and property should use lower camel case notation, so they should start with lowercase, and if made up of multiple words, make the first letter of each word in uppercase. For instance:
var single: Int
var multipleWordsVariable: String

Retrieve the content of series data [] in Highcharts, after rendering the chart?

I would like to add in the click event, a line of code that when I click on the chart, grab the content of the data [] in its series, to save it in a variable for future use.
Which one is the syntax to do so? this.chart.series didn't work.
I am planning to pass this to another chart, as data:
This is what I have so far; tried with get() also but I still get undefined errors
chart: {
renderTo: 'chart',
events: {
click:function(event){
extracteddata=this.chart.get('mainseries');
}
},
}
When I print out in console; the only thing that I get is "this"; which return me the whole chart object including everything inside.
Tried so far with
this.series.option.data
this.data
this.series
And neither return the content of the array. I have printed out "this" and I can clearly see the series.data array which is correctly populated.
this.series is an array of series objects, so assuming you want the first series, use:
events: {
click: function (event) {
var someData = this.series[0].data;
}
}
someData here is an array of point objects. If you want just numbers use
this.series[0].yData
and/or
this.series[0].xData

Resources