Vega plots - showing distribution AND enabling user selection

Is it possible at all to bin values and enable user selection on a chart (vega or not)?

I am binning values using a vega bar chart but selection is disabled, as explained in the documentation.

Docs suggest pre aggregating data first - e.g. with pivot table or transform table - and then using a chart that supports selection. But is there anyway to bin values from the ontology?

To enable selection over the y-axis, aggregate the data in Quiver first (using pivot tables, for example) before passing it into Vega.

Is it about charts in Workshop or Quiver?

I tried both with vega charts - I am flexible, so which ever product enables binning + user selection would work for me.

The vega chart in workshop allows defining an aggregation, or if the aggregation is not expressive enough you can also provide the data to the chart with a function.

Then using the vega-lite option, you can get the selection from the chart :slight_smile:

The vega aggregation is great, but it is not compatible with user selections.
From the documentation (link in my first message).

Vega does not support selection over fields aggregated by Vega

I also add the vega config for completeness.

I think this is an aggregation because “x” applies a count of clients.

I mentioned that the documentation suggests pre aggregating the data before using vega, however, I am not sure what to use to bin values.

A function could work. I did not know that vega is compatible with FoO. Is there an example?

Thanks

{
  "data": {
    "values": $C
  },
  "mark": {
    "type": "bar",
    "clip": true,
    "color": "#62D4A8"
  },
  "encoding": {
    "x": {
      "aggregate": "count",
      "field": $C.client_name,
      "type": "quantitative",
      "axis": {
        "title": "Count of Clients",
        "format": "d",
        "labelExpr": "datum.value % 1 === 0 ? datum.value : ''",
        "grid": false,
        "ticks": false,
        "domain": true,
        "domainColor": "#ccc",
        "domainWidth": 2,
        "labelPadding": 10,
        "zindex": 1
      }
    },
    "y": {
      "bin": { "maxbins": 5 },
      "field": $C.kpi_2024,
      "type": "quantitative",
      "axis": {
        "title": "Total KPI (Binned)",
        "format": "$,.0s",
        "grid": false,
        "ticks": false,
        "domain": true,
        "domainColor": "#ccc",
        "domainWidth": 2,
        "labelPadding": 10,
        "zindex": 1
      }
    }
  }
}

The function output should be a list of structs :slight_smile:

https://www.palantir.com/docs/foundry/workshop/widgets-vega-chart

1 Like

@michaeld this is great, thanks!