Add sorting functionality and index to chart data for improved visualization

This commit is contained in:
2025-01-30 09:39:56 +02:00
parent f2cb82ca81
commit 56e2adbba0
6 changed files with 76 additions and 40 deletions

View File

@@ -22,6 +22,10 @@
"labelAlign": "left", "labelAlign": "left",
"title": null, "title": null,
"labelPadding": 10 "labelPadding": 10
},
"sort": {
"field": "index",
"order": "ascending"
} }
}, },
"y": { "y": {

View File

@@ -23,6 +23,10 @@
"labelAlign": "left", "labelAlign": "left",
"title": null, "title": null,
"labelPadding": 10 "labelPadding": 10
},
"sort": {
"field": "index",
"order": "ascending"
} }
}, },
"y": { "y": {

View File

@@ -15,18 +15,31 @@
"width": 800, "height": 400, "width": 800, "height": 400,
"data": { "data": {
"values": [ "values": [
{"brand": "Samsung", "share": 17.6}, {"index": 1, "brand": "Samsung", "share": 17.6},
{"brand": "Xiaomi", "share": 15.5}, {"index": 2, "brand": "Xiaomi", "share": 15.5},
{"brand": "Apple", "share": 15.0}, {"index": 3, "brand": "Apple", "share": 15.0},
{"brand": "Oppo", "share": 10.2}, {"index": 4, "brand": "Oppo", "share": 10.2},
{"brand": "Vivo", "share": 9.8}, {"index": 5, "brand": "Vivo", "share": 9.8},
{"brand": "Others", "share": 31.9} {"index": 6, "brand": "Others", "share": 31.9}
] ]
}, },
"encoding": { "encoding": {
"theta": {"field": "share", "type": "quantitative", "stack": true}, "theta": {
"color": {"field": "brand", "type": "nominal", "legend": null} "field": "share",
"type": "quantitative",
"stack": true,
"sort": {"field": "index", "order": "ascending"}
},
"color": {
"field": "brand",
"type": "nominal",
"legend": null,
"sort": {"field": "index", "order": "ascending"}
},
"order": {
"field": "index",
"type": "quantitative"
}
}, },
"layer": [{ "layer": [{
"mark": {"type": "arc", "outerRadius": 120} "mark": {"type": "arc", "outerRadius": 120}

View File

@@ -15,17 +15,31 @@
"width": 800, "height": 400, "width": 800, "height": 400,
"data": { "data": {
"values": [ "values": [
{"brand": "Samsung", "share": 17.6}, {"index": 1, "brand": "Samsung", "share": 17.6},
{"brand": "Xiaomi", "share": 15.5}, {"index": 2, "brand": "Xiaomi", "share": 15.5},
{"brand": "Apple", "share": 15.0}, {"index": 3, "brand": "Apple", "share": 15.0},
{"brand": "Oppo", "share": 10.2}, {"index": 4, "brand": "Oppo", "share": 10.2},
{"brand": "Vivo", "share": 9.8}, {"index": 5, "brand": "Vivo", "share": 9.8},
{"brand": "Інші", "share": 31.9} {"index": 6, "brand": "Інші", "share": 31.9}
] ]
}, },
"encoding": { "encoding": {
"theta": {"field": "share", "type": "quantitative", "stack": true}, "theta": {
"color": {"field": "brand", "type": "nominal", "legend": null} "field": "share",
"type": "quantitative",
"stack": true,
"sort": {"field": "index", "order": "ascending"}
},
"color": {
"field": "brand",
"type": "nominal",
"legend": null,
"sort": {"field": "index", "order": "ascending"}
},
"order": {
"field": "index",
"type": "quantitative"
}
}, },
"layer": [{ "layer": [{
"mark": {"type": "arc", "outerRadius": 120} "mark": {"type": "arc", "outerRadius": 120}

View File

@@ -10,37 +10,37 @@
"data": { "data": {
"values": [ "values": [
{ {
"Year": 2009, "Year": "2009-01-01",
"Липовий": 3625, "Липовий": 3625,
"Гречаний": 1908, "Гречаний": 1908,
"Акацієвий": 5201 "Акацієвий": 5201
}, },
{ {
"Year": 2010, "Year": "2010-01-01",
"Липовий": 4227, "Липовий": 4227,
"Гречаний": 2384, "Гречаний": 2384,
"Акацієвий": 5279 "Акацієвий": 5279
}, },
{ {
"Year": 2011, "Year": "2011-01-01",
"Липовий": 5054, "Липовий": 5054,
"Гречаний": 2849, "Гречаний": 2849,
"Акацієвий": 4938 "Акацієвий": 4938
}, },
{ {
"Year": 2012, "Year": "2012-01-01",
"Липовий": 7061, "Липовий": 7061,
"Гречаний": 3501, "Гречаний": 3501,
"Акацієвий": 4585 "Акацієвий": 4585
}, },
{ {
"Year": 2013, "Year": "2013-01-01",
"Липовий": 5570, "Липовий": 5570,
"Гречаний": 3526, "Гречаний": 3526,
"Акацієвий": 4598 "Акацієвий": 4598
}, },
{ {
"Year": 2014, "Year": "2014-01-01",
"Липовий": 5327, "Липовий": 5327,
"Гречаний": 4012, "Гречаний": 4012,
"Акацієвий": 4724 "Акацієвий": 4724
@@ -50,9 +50,10 @@
"encoding": { "encoding": {
"x": { "x": {
"field": "Year", "field": "Year",
"type": "quantitative", "type": "temporal",
"timeUnit": "year",
"axis": { "axis": {
"title": "Рік", "title": "Year",
"titleFontWeight": "bold", "titleFontWeight": "bold",
"grid": true "grid": true
} }

View File

@@ -1,15 +1,15 @@
Country,Speed,Country_UK index,Country,Speed,Country_UK
Australia,79.24,Австралія 1,Australia,79.24,Австралія
China,78.61,Китай 2,China,78.61,Китай
Hong Kong,43.88,Гонконг 3,Hong Kong,43.88,Гонконг
India,13.45,Індія 4,India,13.45,Індія
Indonesia,16.16,Індонезія 5,Indonesia,16.16,Індонезія
Japan,40.51,Японія 6,Japan,40.51,Японія
Malaysia,23.74,Малайзія 7,Malaysia,23.74,Малайзія
New Zealand,92.05,Нова Зеландія 8,New Zealand,92.05,Нова Зеландія
Singapore,68.32,Сінгапур 9,Singapore,68.32,Сінгапур
South Korea,98.93,Південна Корея 10,South Korea,98.93,Південна Корея
Sri Lanka,12.60,Шрі-Ланка 11,Sri Lanka,12.60,Шрі-Ланка
Taiwan,51.67,Тайвань 12,Taiwan,51.67,Тайвань
Thailand,31.38,Таїланд 13,Thailand,31.38,Таїланд
Vietnam,35.33,В'єтнам 14,Vietnam,35.33,В'єтнам
1 index Country Speed Country_UK
2 1 Australia 79.24 Австралія
3 2 China 78.61 Китай
4 3 Hong Kong 43.88 Гонконг
5 4 India 13.45 Індія
6 5 Indonesia 16.16 Індонезія
7 6 Japan 40.51 Японія
8 7 Malaysia 23.74 Малайзія
9 8 New Zealand 92.05 Нова Зеландія
10 9 Singapore 68.32 Сінгапур
11 10 South Korea 98.93 Південна Корея
12 11 Sri Lanka 12.60 Шрі-Ланка
13 12 Taiwan 51.67 Тайвань
14 13 Thailand 31.38 Таїланд
15 14 Vietnam 35.33 В'єтнам