Stacked column chart improvement advise

Dear team,

Thanks to multiple examples found on the forums and youtube i managed to create stacked chart (pix1) in deneb and assign colors to each individul roles. But when filtering different projects, colors keep changing, for example role for KC1 have different colour (pix2). Could you please advise how to fix it?

Also since deneb is really cool, i wonder, is there any easy way to mark “totals” as on pix3?



Thank you

Best regards,

deneb example stacked Comn chart.pbix (1.6 MB)

Hi @vazik.

Here’s some comments:

(1)
To maintain constant role colours when different projects are selected, specify both “domain” and “range” arrays in the “scale” block inside the “color” block.

"color": {
  "field": "Role",
  "sort": [
	"AICT","BI","B.V.","KC1",
	"KC2","KC3","KC4","RPA"
  ],
  "scale": {
	"domain": [
	  "AICT","BI","B.V.","KC1",
	  "KC2","KC3","KC4","RPA"
	],
	"range": [
	  "#93B7D5","red","#D7CBFD","#1E7B9F",
	  "#D59ACE","#98D0A9","#002776","green"
	]
  }
}

(2)
To add totals to each column, add a new “text” mark with a “transform” block containing an “aggregate” calculation for the total, then use the new field.

    {
      "name": "PERIOD_TOTAL",
      "transform": [
        {
          "aggregate": [
            {
              "op": "sum",
              "field": "Žádanky",
              "as": "_total"
            }
          ],
          "groupby": ["Rok/Měsíc"]
        }
      ],
      "mark": {
        "type": "text",
        "color": "black",
        "fontSize": 12,
        "fontWeight": "bold",
        "yOffset": -10
      },
      "encoding": {
        "text": {
          "field": "_total",
          "format": ".1f"
        },
        "y": {
          "field": "_total",
          "type": "quantitative"
        }
      }
    }

Hope it helps.
Greg
eDNA Forum - Deneb Stacked Column Chart.pbix (1.6 MB)

1 Like

Impressive Greg, appreciated!