Not displaying the custom visualization

Trying to make a custom word cloud visualization from the existing index. It is showing error as "Cannot read properties of undefined (reading 'datum')".

{
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "title": "A Wordcloud",
  "width": 900,
  "height": 500,
  "padding": 100,
  "autosize": "none",
  "background": "pink",
  "data": [
    {
      "name": "table",
    "url": {
       "index": "nupur2",
      "body": {
        "aggs": {
          "2": {
            "terms": {"field": "hashtags","order":{"_count": "asc"}, "size": 100},
          "aggs": {
          "_count": {
            "avg": {"field": "vaderSentiment"}
          }
          }
          }
        }
      }
    },
      "format": {"property": "aggregations.2.buckets"},
      "transform": [
        {
          "type": "formula",
          "as": "angle",
          "expr": "datum.size >= 3 ? 0 : [-45,-30, -15, 0, 15, 30, 45][floor(random() * 7)]"
        },
        {
          "type": "formula", "as": "angle",
          "expr": "[-45, 0, 45][~~(random() * 3)]"
        },
        {
          "type": "formula", "as": "weight",
          "expr": "if(datum.text=='VEGA', 600, 300)"
        }
      ]
    }
  ],
   "scales": [
    {
      "name": "color",
      "type": "ordinal",
      "domain": {"data": "table", "field": "hashtags"},
      "range": ["green", "orange", "red"]
    }
  ],
  "marks": [
    {
      "type": "group",
      "from": {"data": "table"},
      "encode": {
        "enter": {
          "text": {"field": "hashtags"},
          "align": {"value": "center"},
          "baseline": {"value": "alphabetic"},
          "fill": {"scale": "color", "field": "hashtags"}
        },
        "update": {
          "fillOpacity": {"value": 1}
        },
        "hover": {
          "fillOpacity": {"value": 0.5}
        }
      },
      "transform": [
        {
          "type": "wordcloud",
          "size": [800, 400],
          "text": {"field": "hashtags"},
          "rotate": {"field": "datum.angle"},
          "font": "Helvetica Neue, Arial",
          "fontSize": {"field": "datum.count"},
          "fontWeight": {"field": "datum.weight"},
          "fontSizeRange": [12, 56],
          "padding": 2
        }
      ]
    }
  ]
}

You are mixing things (I guess from pasted code elsewhere).

This is a working example using the kibana flights sample dataset

{
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "title": "Weather",
  "data": {
    "name": "table",
    "url": {
      "%context%": true
      "%timefield%": "timestamp",
      "index": "kibana_sample_data_flights",
      "body": {
        "aggs": {
          "my_terms": {
            "terms": {
              "field": "DestCityName",
              "order": {
                "_count": "desc"
              },
              "size": 100
            }
          }
        },
        "size": 0,
      }
    },
    "format": {"property": "aggregations.my_terms.buckets"}
  },
  "scales": [
    {
      "name": "color",
      "type": "ordinal",
      "domain": {"data": "table", "field": "key"},
      "range": ["#d5a928", "#652c90", "#939597"]
    }
  ],
  "marks": [
    {
      "type": "text",
      "from": {"data": "table"},
      "encode": {
        "enter": {
          "text": {"field": "key"},
          "align": {"value": "center"},
          "baseline": {"value": "alphabetic"},
          "fill": {"scale": "color", "field": "key"}
        },
        "update": {
          "fillOpacity": {"value": 1}
        },
        "hover": {
          "fillOpacity": {"value": 0.5}
        }
      },
      "transform": [
        {
          "type": "wordcloud",
          "size": [800, 400],
          "text": {"field": "text"},
          "font": "Helvetica Neue, Arial",
          "fontSize": {"field": "datum.doc_count"},
          "fontSizeRange": [12, 56],
          "padding": 2
        }
      ]
    }
  ]
}

This example (copied also from Vega official word cloud example) does not randomizes the angles or sets ups any weight for the labels. It also runs a terms aggregation to count the destination cities and takes into account the kibana search and time range selections.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.