Vizzu provides multiple options to sort data. By default, the data is sorted by the order it is added to Vizzu. This is why we suggest to add temporal data such as dates in chronological order - from oldest to newest.
You can also sort the elements by value, which will provide you with an ascending order.
from ipyvizzu import Chart, Data, Config
data = Data()
data.add_dimension('Genres', [ 'Pop', 'Rock', 'Jazz', 'Metal'])
data.add_dimension('Types', [ 'Hard', 'Smooth', 'Experimental' ])
data.add_measure(
'Popularity',
[
[114, 96, 78, 52],
[56, 36, 174, 121],
[127, 83, 94, 58],
]
)
chart = Chart()
chart.animate(data)
chart.animate(Config({"channels": {"y": {"set": "Popularity"}, "x": {"set": "Genres"}}}))
chart.animate(Config({"channels": {"label": {"attach": ["Popularity"]}}}))
chart.animate(Config({"color": {"set": ["Genres"]}}))
chart.animate(Config({
"sort": "byValue",
}))
chart.show()
If you want descending order instead, you have to set the reverse parameter to true. When used without setting the sorting to byValue, the elements will be in the opposite order than they are in the data set added to Vizzu.
from ipyvizzu import Chart, Data, Config
data = Data()
data.add_dimension('Genres', [ 'Pop', 'Rock', 'Jazz', 'Metal'])
data.add_dimension('Types', [ 'Hard', 'Smooth', 'Experimental' ])
data.add_measure(
'Popularity',
[
[114, 96, 78, 52],
[56, 36, 174, 121],
[127, 83, 94, 58],
]
)
chart = Chart()
chart.animate(data)
chart.animate(Config({"channels": {"y": {"set": "Popularity"}, "x": {"set": "Genres"}}}))
chart.animate(Config({"channels": {"label": {"attach": ["Popularity"]}}}))
chart.animate(Config({"color": {"set": ["Genres"]}}))
chart.animate(Config({
"sort": "byValue",
"reverse": True,
}))
chart.show()
This is how to switch back to the default sorting
from ipyvizzu import Chart, Data, Config
data = Data()
data.add_dimension('Genres', [ 'Pop', 'Rock', 'Jazz', 'Metal'])
data.add_dimension('Types', [ 'Hard', 'Smooth', 'Experimental' ])
data.add_measure(
'Popularity',
[
[114, 96, 78, 52],
[56, 36, 174, 121],
[127, 83, 94, 58],
]
)
chart = Chart()
chart.animate(data)
chart.animate(Config({"channels": {"y": {"set": "Popularity"}, "x": {"set": "Genres"}}}))
chart.animate(Config({"channels": {"label": {"attach": ["Popularity"]}}}))
chart.animate(Config({"color": {"set": ["Genres"]}}))
chart.animate(Config({
"sort": "byValue",
"reverse": True,
}))
chart.animate(Config({
"sort": "none",
"reverse": False,
}))
chart.show()
When you have more than one dimension on a channel, their order determines how the elements are grouped.
from ipyvizzu import Chart, Data, Config
data = Data()
data.add_dimension('Genres', [ 'Pop', 'Rock', 'Jazz', 'Metal'])
data.add_dimension('Types', [ 'Hard', 'Smooth', 'Experimental' ])
data.add_measure(
'Popularity',
[
[114, 96, 78, 52],
[56, 36, 174, 121],
[127, 83, 94, 58],
]
)
chart = Chart()
chart.animate(data)
chart.animate(Config({"channels": {"y": {"set": "Popularity"}, "x": {"set": "Genres"}}}))
chart.animate(Config({"channels": {"label": {"attach": ["Popularity"]}}}))
chart.animate(Config({"color": {"set": ["Genres"]}}))
chart.animate(Config({
"channels": {
"y": {"detach": ["Types"]},
"x": {"set": ["Genres", "Types"]},
}
}))
chart.show()
When switching the order of dimensions on the x-axis Vizzu will rearrange the elements according to this new logic.
from ipyvizzu import Chart, Data, Config
data = Data()
data.add_dimension('Genres', [ 'Pop', 'Rock', 'Jazz', 'Metal'])
data.add_dimension('Types', [ 'Hard', 'Smooth', 'Experimental' ])
data.add_measure(
'Popularity',
[
[114, 96, 78, 52],
[56, 36, 174, 121],
[127, 83, 94, 58],
]
)
chart = Chart()
chart.animate(data)
chart.animate(Config({"channels": {"y": {"set": "Popularity"}, "x": {"set": "Genres"}}}))
chart.animate(Config({"channels": {"label": {"attach": ["Popularity"]}}}))
chart.animate(Config({"color": {"set": ["Genres"]}}))
chart.animate(Config({
"channels": {
"y": {"detach": ["Types"]},
"x": {"set": ["Genres", "Types"]},
}
}))
chart.animate(Config({
"channels": {
"x": {"set": ["Types", "Genres"]},
}
}))
chart.show()