Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hi
I'm traing replicat this chart https://powerbi.microsoft.com/en-us/blog/politico-europe-bets-on-microsoft-power-bi-to-report-on-the...
And I can make the chart but, the order of party it's not the correct. How I 'can change the order?
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"width": 420,
"height": 210,
"signals": [
{
"name": "parties",
"update": "['PSOE','PP','VOX', 'UP', 'Cs', 'ERC', 'Junts', 'PNV', 'Más País', 'EHB', 'CUP', 'Podemos-EU-Anova', 'Compromís', 'CC','BNG','NA+', 'PRC', 'TE', 'ECP']"
},
{
"name": "partyColors",
"update": "['#e4010b', '#0055a6', '#59c136', '#68327f', '#fa4e00', '#ffc03f', '#02c2b3', '#009526', '#00e2c6', '#c4d600', '#fff200', '#68327f', '#0fddc4', '#ffd700', '#adcfef', '#e3021d', '#c2ce0c', '#037252', '#68327f']"
},
{
"name": "dataLength",
"update": "length(data('dataset'))"
},
{
"name": "row0Radius",
"value": 280
},
{
"name": "row1Radius",
"value": 260
},
{
"name": "row2Radius",
"value": 240
},
{
"name": "row3Radius",
"value": 220
},
{
"name": "row4Radius",
"value": 200
},
{
"name": "row5Radius",
"value": 180
},
{
"name": "row6Radius",
"value": 160
},
{
"name": "row0Circ",
"update": "PI*row0Radius"
},
{
"name": "row1Circ",
"update": "PI*row1Radius"
},
{
"name": "row2Circ",
"update": "PI*row2Radius"
},
{
"name": "row3Circ",
"update": "PI*row3Radius"
},
{
"name": "row4Circ",
"update": "PI*row4Radius"
},
{
"name": "row5Circ",
"update": "PI*row5Radius"
},
{
"name": "row6Circ",
"update": "PI*row6Radius"
},
{
"name": "totalLength",
"update": "row0Circ+row1Circ+row2Circ+row3Circ+row4Circ+row5Circ+row6Circ "
}
],
"data": [
{
"name": "dataset",
"transform": [
{
"type": "project",
"fields": [
"Mandates",
"Party",
"Full Opacity By Slicer"
]
},
{
"type": "formula",
"expr": "datum['Party'] === 'PSOE' ? 1 : datum['Party'] === 'PP' ? 2 : datum['Party'] === 'VOX' ? 3 : datum['Party'] === 'UP' ? 4 : datum['Party'] === 'Cs' ? 5 : datum['Party'] === 'ERC' ? 6 : datum['Party'] === 'ECP' ? 7 : datum['Party'] === 'Junts' ? 8 : datum['Party'] === 'PNV' ? 9 : datum['Party'] === 'Más País' ? 10 : datum['Party'] === 'EHB' ? 11 : datum['Party'] === 'CUP' ? 12: datum['Party'] === 'Podemos-EU-Anova' ? 13 : datum['Party'] === 'Compromís' ? 14 : datum['Party'] === 'CC' ? 15 : datum['Party'] === 'BNG' ? 16 : datum['Party'] === 'NA+' ? 17 : datum['Party'] === 'PRC' ? 19:datum['Party'] === 'TE' ? 19 : null ",
"as": "party_sort"
},
{
"type": "collect",
"sort": {
"field": "party_sort"
}
},
{
"type": "formula",
"expr": "sequence(0, datum['Mandates'], 1)",
"as": "index"
},
{
"type": "flatten",
"fields": ["index"],
"as": ["index"]
},
{
"type": "window",
"ops": ["row_number"],
"fields": [null],
"as": ["index"],
"sort": {
"field": "Party",
"order": "ascending"
}
}
]
},
{
"name": "placement",
"transform": [
{
"type": "sequence",
"start": 1,
"stop": {
"signal": "dataLength+1"
},
"as": "index"
},
{
"type": "formula",
"as": "wholeCirc",
"expr": "totalLength/dataLength"
},
{
"type": "window",
"ops": ["sum"],
"fields": ["wholeCirc"],
"as": ["cumWholeCirc"]
},
{
"type": "formula",
"as": "row",
"expr": "datum.cumWholeCirc <row0Circ?0:datum.cumWholeCirc <row0Circ+row1Circ?1:datum.cumWholeCirc <row0Circ+row1Circ+row2Circ?2:datum.cumWholeCirc <row0Circ+row1Circ+row2Circ+row3Circ?3:datum.cumWholeCirc <row0Circ+row1Circ+row2Circ+row3Circ+row4Circ?4:datum.cumWholeCirc <row0Circ+row1Circ+row2Circ+row3Circ+row4Circ+row5Circ?5:6 "
},
{
"type": "joinaggregate",
"fields": ["Mandates"],
"ops": ["count"],
"groupby": ["row"],
"as": ["rowCount"]
},
{
"type": "formula",
"as": "rowCirc",
"expr": "datum.row==0?(row0Circ/(datum.rowCount-1)):datum.row==1?(row1Circ/(datum.rowCount-1)):datum.row==2?(row2Circ/(datum.rowCount-1)):datum.row==3?(row3Circ/(datum.rowCount-1)):datum.row==4?(row4Circ/(datum.rowCount-1)):datum.row==5?(row5Circ/(datum.rowCount-1)):datum.row==6?(row6Circ/(datum.rowCount-1)):0"
},
{
"type": "window",
"ops": ["sum"],
"fields": ["rowCirc"],
"groupby": ["row"],
"sort": {
"field": "index",
"order": "descending"
},
"as": ["cumRowCirc"]
},
{
"type": "formula",
"as": "cumRowCircAct",
"expr": "datum.cumRowCirc - datum.rowCirc "
},
{
"type": "formula",
"as": "theta",
"expr": "datum.cumRowCircAct==0?0:datum.row==0?(datum.cumRowCircAct/row0Radius):datum.row==1?(datum.cumRowCircAct/row1Radius):datum.row==2?datum.cumRowCircAct/row2Radius:datum.row==3?datum.cumRowCircAct/row3Radius:datum.row==4?datum.cumRowCircAct/row4Radius:datum.row==5?datum.cumRowCircAct/row5Radius:datum.row==6?datum.cumRowCircAct/row6Radius:0"
},
{
"type": "formula",
"as": "x",
"expr": "datum.row==0?row0Radius*cos(datum.theta):datum.row==1?row1Radius*cos(datum.theta):datum.row==2?row2Radius*cos(datum.theta):datum.row==3?row3Radius*cos(datum.theta):datum.row==4?row4Radius*cos(datum.theta):datum.row==5?row5Radius*cos(datum.theta):datum.row==6?row6Radius*cos(datum.theta):0"
},
{
"type": "formula",
"as": "y",
"expr": "datum.row==0?row0Radius*sin(datum.theta):datum.row==1?row1Radius*sin(datum.theta):datum.row==2?row2Radius*sin(datum.theta):datum.row==3?row3Radius*sin(datum.theta):datum.row==4?row4Radius*sin(datum.theta):datum.row==5?row5Radius*sin(datum.theta):datum.row==6?row6Radius*sin(datum.theta):0"
},
{
"type": "window",
"sort": {
"field": "theta",
"order": "ascending"
},
"ops": ["row_number"],
"fields": ["row_number"],
"as": ["lookup"]
},
{
"type": "lookup",
"from": "dataset",
"key": "index",
"fields": ["lookup"],
"values": [
"Party",
"Full Opacity By Slicer"
],
"as": [
"Party",
"Full Opacity By Slicer"
]
}
]
}
],
"scales": [
{
"name": "x",
"type": "linear",
"round": true,
"nice": true,
"zero": true,
"domain": {
"field": "x",
"data": "placement"
},
"range": "width"
},
{
"name": "y",
"type": "linear",
"round": true,
"nice": true,
"zero": true,
"domain": {
"field": "y",
"data": "placement"
},
"range": "height"
},
{
"name": "color",
"type": "ordinal",
"domain": {"signal": "parties"},
"range": {"signal": "partyColors"}
}
],
"marks": [
{
"name": "marks",
"type": "symbol",
"from": {"data": "placement"},
"encode": {
"enter": {
"x": {
"scale": "x",
"field": "x"
},
"y": {
"scale": "y",
"field": "y"
},
"shape": {"value": "circle"},
"size": {"value": 130},
"stroke": {"value": "grey"},
"tooltip": [
{
"title": "Party",
"field": "Party",
"type": "nominal"
}
],
"fill": {
"type": "ordinal",
"field": "Party",
"scale": "color"
}
},
"update": {
"opacity": {
"signal": "datum['Full Opacity By Slicer']===true?1:0.15"
}
}
}
},
{
"type": "text",
"data": [{}],
"encode": {
"update": {
"text": {
"signal": "dataLength"
},
"align": {"value": "center"},
"fill": {"value": "#595959"},
"x": {"signal": "width /2"},
"y": {"signal": "height -20"},
"fontSize": {"value": 60},
"fontWeight": {
"value": "bold"
},
"font": {
"value": "sans-serif"
}
}
}
},
{
"type": "text",
"data": [{}],
"encode": {
"update": {
"text": {
"value": ["Total Seats"]
},
"align": {"value": "center"},
"fill": {"value": "#595959"},
"x": {"signal": "width /2"},
"y": {"signal": "height -80"},
"fontSize": {"value": 19},
"fontWeight": {
"value": "normal"
},
"font": {
"value": "sans-serif"
}
}
}
}
]
}
Solved! Go to Solution.
Hi @danextian I got it.
I have to change this part and put the attribute and order of this.
{
"type": "window",
"ops": ["row_number"],
"fields": [null],
"as": ["index"],
"sort": {
"field": "party_sort",
"order": "descending"
}
Hi @danextian I got it.
I have to change this part and put the attribute and order of this.
{
"type": "window",
"ops": ["row_number"],
"fields": [null],
"as": ["index"],
"sort": {
"field": "party_sort",
"order": "descending"
}
Hi @Merinoide ,
It looks like your party sort column is not in the correct data type. It is a text string instead of a number. A number column would be italicized and right aligned. Try chaging the data type in Power Query and see it goes.
The number columns below are italicized and right-aligned.
Hi @danextian thanks for your answer.
Looks like that the type of value it's not the reason
I changed this but... nothing
User | Count |
---|---|
83 | |
75 | |
72 | |
42 | |
36 |
User | Count |
---|---|
114 | |
56 | |
52 | |
43 | |
42 |