Skip to content

Latest commit

 

History

History
44 lines (36 loc) · 1.24 KB

File metadata and controls

44 lines (36 loc) · 1.24 KB

Histogram Chart

Goal

In this guide, we will create a Histogram Chart that subdivides a numerical range into bins, and counts the number of data points within each segment. The resulting bar chart provides a discrete estimate of the probability density function.

histogram_chart

Full code example

CustomChart {
  fields {
    field grain {
      type: 'dimension'
    }
    field metric {
      type: 'dimension' // this type can be dimenson or measure depends on the type of field that you want to create the histogram on
    }
  }
  template: @vgl
  {
    "data": {"values": @{values}},
    "transform": [
      {"bin": {"maxbins": 40}, "field": @{fields.metric.name}, "as": "binned_price"}
    ],
    "mark": {
      "type": "bar",
      "tooltip": true
    },
    "encoding": {
      "x": {"field": "binned_price", "type": "quantitative", "bin": {"binned": true, "step": 20}},
      "x2": {"field": "binned_price_end"},
      "y": {"aggregate": "count"}
    }
  }
  ;;
}

Applying the chart

applying_histogram_custom_chart