CharlesH
CharlesH

Reputation: 13

VisJS graph2d draw order / groupOrder

Is there an equivalent groupOrder option for graph2d as there is for the timeline widget? http://visjs.org/docs/timeline/#Configuration_Options

Looking to draw bar charts in a specific order to handle overlapping.

Upvotes: 0

Views: 320

Answers (1)

JorisP
JorisP

Reputation: 46

The group order is determined by the order how you add groups, unless you set the ids as integers.

This is a example where you set the ids with strings:

a = new vis.DataSet()
-> DataSet {_options: Object, _data: Object, length: 0, _fieldId: "id", _type: Object…}
a.add([{id:"b"}, {id: "a"}, {id: "c"}])
-> ["b", "a", "c"]
a.getIds()
-> ["b", "a", "c"]

But when you create a dataset where the ids are integers, it will sort the datagroups based on the integers:

b = new vis.DataSet()
-> DataSet {_options: Object, _data: Object, length: 0, _fieldId: "id", _type: Object…}
b.add([{id:2}, {id: 3}, {id: 1}])
-> [2, 3, 1]
b.getIds()
-> [1, 2, 3]

When you mix the integers and strings it will sort the integers first and then then leave the strings unsorted.

c = new vis.DataSet()
DataSet {_options: Object, _data: Object, length: 0, _fieldId: "id", _type: Object…}
c.add([{id:"b"}, {id: 2}, {id: "a"} , {id: 1}])
["b", 2, "a", 1]
c.getIds()
[1, 2, "b", "a"]

Upvotes: 2

Related Questions