Custom week labels with unordered result - core-plot

I am using Core Plot to draw a graph with custom labels.
It has 7 labels with week such as "Sun", "Mon" and "Tue". And the label may start with each day.
I have ordered the sequence in a NSMutableSet or NSMutableOrderedSet and then assign to x.axisLabels.
However, the axisLables is an unordered NSSet so my labels get unordered, too.
For example, I set the sequence with string:
"Mon", "Thu", "Wed", "Thu", "Fri", "Sat", "Sun".
But the graph shows the sequence:
"Sat", "Sun", "Mon", "Thu", "Wed", "Thu", "Fri".
Definition of axisLabels in core plot.
#property (nonatomic, readwrite, retain) NSSet *axisLabels;
Any suggestions for me? Thanks.

Sets have no defined order. Core Plot uses the tickLocation of each label to position them along the axis.

Related

Changing Sparkline color based on another cell's value

I have a sparkline that shows how complete an event is. I would like the color to change based on the value in another cell.
If the value is less than 50, I want it to be red;
If the value is greater than 51, but less than 75, I want it to be yellow; and - If the value is greater than 76, I want it to be green.
What would be the syntax for that?
I've tried nested if statements, but receive the message that only 3 arguments are allowed.
This is the formula I've tried:
=SPARKLINE((COUNTIF(H4:H14,"yes")/counta(H4:H14)*100),{"charttype","bar";"color1",if(E2<50, "red",if(E2>51, but E2<75, "yellow",if(E2>76, "green")));"max",100})
=SPARKLINE((COUNTIF(H4:H14,"yes")/COUNTA(H4:H14)*100),
{"charttype", "bar";
"color1", IF(E2>76, "green",
IF(E2>51, "yellow", "red"));
"max", 100})

Add items from a String:Int dictionary to UITableView on iOS using Swift

In my Swift-written iOS app, I have a UITableView with one UILabel in every row. Besides that, I also have a Dictionary of [String:Int] type.
I want each UILabel in the rows of UITableView to contain the String value from the dictionary. Each row will be as much times as the Int value represents.
For example, let's say I have this dictionary:
var dict: [String:Int] = ["apple": 2, "Banana": 3, "Orange": 7]
So in the UITableView I need to have 2 rows with Apple label in them, 3 rows with Banana label in them, and 7 rows with Orange label in them.
How can I accomplish that in the tableView(cellForRowAt:) method?
First of all you need an array as data source to return the proper values for the delegate methods numberOfRows and cellForRow.
To convert the dictionary to a suitable array use something like this
let dict = ["apple": 2, "Banana": 3, "Orange": 7]
var fruit = [String]()
for key in dict.keys.sorted(by: {$0.lowercased() < $1.lowercased() }) {
let value = dict[key]!
for _ in 0..<value {
fruit.append(key)
}
} // result: ["apple", "apple", "Banana", "Banana", "Banana", "Orange", "Orange", "Orange", "Orange", "Orange", "Orange", "Orange"]

How to draw clickable grid objects inside zoomable scrollview taken datas from remote json data?

I want to draw clickable grid objects inside zoomable scrollview taken datas from remote json data my example remote json file data under below;
Json data explode means;
0 = Empty object not show object in view
1 = Show object with title and background not empty object
[
{
"Base": "A",
"Seats": "A1*0*,A2*1*,A3*1*,A4*1*,A5*0*,A6*0*"
},
{
"Base": "B",
"Seats": "B1*1*,B2*1*,B3*1*,B4*0*,B5*0*,B6*0*,B7*1*"
},
{
"Base": "C",
"Seats": "C1*0*,C2*0*,C3*0*,C4*0*,C5*0*,C6*0*,C7*1*,C8*1*,C9*1*,C10-C11*1*"
}
]
Also i have remote json parsing codes i take json arrays to my under below arrays successfuly ;
var Base = [""]
var Seats = [""]
Will shows in my zoomable scrollview inside that json like under below;
1 2 3 4 5 6 7 8 9 10 11
A A2 A3 A4
B B1 B2 B3 B7
C C7 C8 C9 C10-C11
Not empty objects like an A2,A3,A4 must be square width : 20 height : 20 with green background clickable object. When i click in my view i can change backgroud color it to like red etc..
Also C10-C11 MUST BE double widthx 2 so that seats double seats.you can see comming json value.
How can i do this i try collectionview but dont have zoom feature ? I think i need to do with cgrect somethings ?
Thank you !
Is your json file format fixed or can it be customised ? it does not seems well prepared for what you expect.
You don't need to have A B C section and repeat the Section name in the grid item. As in the Battleship game, the name of each cell is expressed by the column and row title. So if you can format this:
[{ "A":"0","1","1","1","0","0"... },{ "B":"1","1","1","0"...},{"C" : ..."0","1","1","1",**"2"**}]
(NB: this works only if seat can be only doubled horizontally)
Now you create two arrays : One with bases names by getting the dictionary (from the JSON) keys:
let bases = jsonDict.allKeys
and an other with all the data in it: let seats = jsonDict
Now you should loop twice:
First in the base array then in the seats array for each base entry.
Each time you check the value of seats[bases[index in base loop]][index in the seat loop] to get the value. If it is 0 you continue, if it is 1 you create a square view and add it to the scrollview. the same if it 2 with a doubled width square view.
To set the position of the square view (or rectangle if value is 2) you use the loop index. Bases are rows and seats are columns. The anchor point of the square view will be x:0 for index 0 in the seats loop and y:0 for the A base, will be x:20 * loop index of the seats loop and y: 20 * loop index of the bases loop. Width will be value * 20 and height always 20.
And then you manage clicks and colour states in the square view itself by handling touch event on it.
Don't forget to set the contentSize of your scrollview to CGSize(width: base[0].count * 20, height: bases.count * 20
Let me know if it help.

If I remove an item from NSMutableArray, will the index of the items be updated?

Say, I have a NSMutableArray which contains 5 items.
NSMutableArray *fruitArray = [NSMutableArray arrayWithArray:#[#"Apple", #"Pear", #"Peach", #"Banana", #"Orange"]];
Now if I remove the third item - Peach from the array, will the index of Banana and Orange change from 3, 4 to 2, 3 respectively?
Thanks
Yes. Did you bother to read the documentation?
To fill the gap, all elements beyond index are moved by subtracting 1 from their index.

Highcharts series data

I am using fro drawing my spline chart. here is my series data example array:
data: [
[1371563990000,1,530,100],[1373204470000,2,529,0],[1373464877000,0.5,531,50]
]
.
I want to access the fourth index value for the selected series. I am using this.series.data[this.myIndex].config['z'] to get the third index value but don't know how to get the fourth index value.
Thanks in advance
You need to use object, instead of array,
{
x: 1371563990000,
y: 1,
customParam1: 530,
customParam2: 100
}
Paramaters will be available in point.options.customParam1

Resources