Forum Discussion

yougainnothing's avatar
yougainnothing
Frequent Visitor
3 years ago
Solved

Beginner DENEB assistance - heat map

Hi,

 

I'm very new to deneb and trying to learn, however I for some reason just cannot get this to work, it comes up with the error message: 

Invalid field type "undefined".

I am using a column which is a datetime (ScanEventTime) and a measure which is a whole number (drops)


{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {"name": "dataset"},
"transform": [{
"filter": {"and": [
{"field": "drops", "valid": true},
{"field": "ScanEventTime", "valid": true}
]}
}],
"mark": "rect",
"width": 300,
"height": 200,
"encoding": {
"x": {
"bin": {"maxbins":60},
"timeUnit":"hours",
"field": "drops",
"type": "quantitative"
},
"y": {
"bin": {"maxbins": 40},
"timeUnit":"day",
"field": "ScanEventTime",
"type": "date"
},
"color": {
"aggregate": "drops",
"type": "quantitative"
}
},
"config": {
"view": {
"stroke": "transparent"
}
}
}

  • giammariam's avatar
    giammariam
    3 years ago

    Hey yougainnothing, will something like the following work? You can adjust the day domain and the hour domain in the params at the top of the spec. In Deneb you would just remove the values array from the data property. It sounds like you're wanting to bring two fields into Deneb: ScanEventTime and Drops. It doesn't seem like DropID is needed in Deneb since you're calculating the distinct count inside a measure outside  of Deneb. Let me know if I have any of this wrong. Also, if you're looking for a particular design, consider providing a rough mockup image or example. 

    Let me know if this is enough to get you going.

    Gist: https://vega.github.io/editor/#/gist/ef451d7b991d4e24bcc6b039829f780c/spec.json

    spec: 

    {
      "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
      "params": [
        {
          "name": "days",
          "value": ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
        },
        {"name": "hours", "expr": "sequence(8,21,1)"}
      ],
      "data": {
        "name": "dataset",
        "values": [
          {"ScanEventTime": "7/7/23 7:11", "DropID": 1425, "drops": 3},
          {"ScanEventTime": "7/7/23 8:11", "DropID": 1461, "drops": 5},
          {"ScanEventTime": "7/3/23 8:11", "DropID": 1504, "drops": 7},
          {"ScanEventTime": "7/3/23 8:11", "DropID": 1052, "drops": 12},
          {"ScanEventTime": "7/3/23 10:11", "DropID": 1210, "drops": 2},
          {"ScanEventTime": "7/3/23 11:11", "DropID": 1210, "drops": 8},
          {"ScanEventTime": "7/3/23 11:11", "DropID": 1210, "drops": 5},
          {"ScanEventTime": "7/5/23 12:11", "DropID": 1943, "drops": 16},
          {"ScanEventTime": "7/5/23 13:11", "DropID": 1707, "drops": 6},
          {"ScanEventTime": "7/5/23 15:11", "DropID": 1331, "drops": 1},
          {"ScanEventTime": "7/6/23 10:11", "DropID": 1410, "drops": 8},
          {"ScanEventTime": "7/6/23 11:11", "DropID": 1410, "drops": 3},
          {"ScanEventTime": "7/6/23 12:11", "DropID": 1410, "drops": 20},
          {"ScanEventTime": "7/6/23 13:11", "DropID": 1410, "drops": 5},
          {"ScanEventTime": "7/4/23 10:11", "DropID": 1410, "drops": 3},
          {"ScanEventTime": "7/4/23 11:11", "DropID": 1410, "drops": 9},
          {"ScanEventTime": "7/4/23 12:11", "DropID": 1410, "drops": 18},
          {"ScanEventTime": "7/4/23 13:11", "DropID": 1410, "drops": 9},
          {"ScanEventTime": "7/4/23 14:11", "DropID": 1410, "drops": 2}
        ]
      },
      "transform": [
        {"calculate": "utcday(datum['ScanEventTime'])", "as": "day_num"},
        {
          "calculate": "dayAbbrevFormat(utcday(datum['ScanEventTime']))",
          "as": "day_name"
        },
        {"calculate": "utchours(datum['ScanEventTime'])", "as": "hour"}
      ],
      "mark": "rect",
      "width": 300,
      "height": 200,
      "encoding": {
        "x": {
          "field": "hour",
          "type": "nominal",
          "axis": {"labelAngle": 0, "title": "Hour"},
          "scale": {"domain": {"expr": "hours"}}
        },
        "y": {
          "field": "day_name",
          "type": "nominal",
          "scale": {"domain": {"expr": "days"}},
          "axis": {"title": "Day"}
        },
        "color": {
          "field": "drops",
          "type": "quantitative",
          "legend": {"title": "Drops"}
        }
      },
      "config": {"view": {"stroke": "transparent"}}
    }

     

9 Replies

  • Also for the color encoding, in the aggregate property you should be specifying the type of aggregation (i.e. min, max, sum, etc.). You specify which data field to use in the encoding with the field property.

     

    so instead of

    color": {
    "aggregate": "drops",
    "type": "quantitative"
    }

    you would do something like

    "color": {
        "aggregate": "sum",
        "field": "drops",
        "type": "quantitative"
    }

     

    • giammariam's avatar
      giammariam
      Icon for Solution Sage rankSolution Sage

      Hey yougainnothing, will something like the following work? You can adjust the day domain and the hour domain in the params at the top of the spec. In Deneb you would just remove the values array from the data property. It sounds like you're wanting to bring two fields into Deneb: ScanEventTime and Drops. It doesn't seem like DropID is needed in Deneb since you're calculating the distinct count inside a measure outside  of Deneb. Let me know if I have any of this wrong. Also, if you're looking for a particular design, consider providing a rough mockup image or example. 

      Let me know if this is enough to get you going.

      Gist: https://vega.github.io/editor/#/gist/ef451d7b991d4e24bcc6b039829f780c/spec.json

      spec: 

      {
        "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
        "params": [
          {
            "name": "days",
            "value": ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
          },
          {"name": "hours", "expr": "sequence(8,21,1)"}
        ],
        "data": {
          "name": "dataset",
          "values": [
            {"ScanEventTime": "7/7/23 7:11", "DropID": 1425, "drops": 3},
            {"ScanEventTime": "7/7/23 8:11", "DropID": 1461, "drops": 5},
            {"ScanEventTime": "7/3/23 8:11", "DropID": 1504, "drops": 7},
            {"ScanEventTime": "7/3/23 8:11", "DropID": 1052, "drops": 12},
            {"ScanEventTime": "7/3/23 10:11", "DropID": 1210, "drops": 2},
            {"ScanEventTime": "7/3/23 11:11", "DropID": 1210, "drops": 8},
            {"ScanEventTime": "7/3/23 11:11", "DropID": 1210, "drops": 5},
            {"ScanEventTime": "7/5/23 12:11", "DropID": 1943, "drops": 16},
            {"ScanEventTime": "7/5/23 13:11", "DropID": 1707, "drops": 6},
            {"ScanEventTime": "7/5/23 15:11", "DropID": 1331, "drops": 1},
            {"ScanEventTime": "7/6/23 10:11", "DropID": 1410, "drops": 8},
            {"ScanEventTime": "7/6/23 11:11", "DropID": 1410, "drops": 3},
            {"ScanEventTime": "7/6/23 12:11", "DropID": 1410, "drops": 20},
            {"ScanEventTime": "7/6/23 13:11", "DropID": 1410, "drops": 5},
            {"ScanEventTime": "7/4/23 10:11", "DropID": 1410, "drops": 3},
            {"ScanEventTime": "7/4/23 11:11", "DropID": 1410, "drops": 9},
            {"ScanEventTime": "7/4/23 12:11", "DropID": 1410, "drops": 18},
            {"ScanEventTime": "7/4/23 13:11", "DropID": 1410, "drops": 9},
            {"ScanEventTime": "7/4/23 14:11", "DropID": 1410, "drops": 2}
          ]
        },
        "transform": [
          {"calculate": "utcday(datum['ScanEventTime'])", "as": "day_num"},
          {
            "calculate": "dayAbbrevFormat(utcday(datum['ScanEventTime']))",
            "as": "day_name"
          },
          {"calculate": "utchours(datum['ScanEventTime'])", "as": "hour"}
        ],
        "mark": "rect",
        "width": 300,
        "height": 200,
        "encoding": {
          "x": {
            "field": "hour",
            "type": "nominal",
            "axis": {"labelAngle": 0, "title": "Hour"},
            "scale": {"domain": {"expr": "hours"}}
          },
          "y": {
            "field": "day_name",
            "type": "nominal",
            "scale": {"domain": {"expr": "days"}},
            "axis": {"title": "Day"}
          },
          "color": {
            "field": "drops",
            "type": "quantitative",
            "legend": {"title": "Drops"}
          }
        },
        "config": {"view": {"stroke": "transparent"}}
      }

       

      • yougainnothing's avatar
        yougainnothing
        Frequent Visitor

        This has worked perfectly! Thank you so much, I think I can take it from here to where it needs to be.

  • Hey yougainnothing, no need to apologize. Happy to help, and thanks for tagging me. I appreciate you sharing your vega-lite spec, could you provide a sample dataset? Here's how

    • yougainnothing's avatar
      yougainnothing
      Frequent Visitor

      Thank you so much, below is the sample data.

       

      The measure 'drops' is 

      drops = DISTINCTCOUNT('Events'[DropId])

       

      ScanEventTime (DateTime)DropID (Whole Number)
      07/02/2023 10:11:3412345678
      07/02/2023 13:12:5512345679
      08/02/2023 10:10:1012345680
      08/02/2023 10:10:1112345681
      08/02/2023 10:23:1112345682
      08/02/2023 10:25:3412345683
      08/02/2023 10:59:1212345684
      09/02/2023 12:35:1012345685
      09/02/2023 12:36:4612345686
      09/02/2023 12:37:3412345687
      09/02/2023 13:40:1012345688
      09/02/2023 13:17:2412345689
      09/02/2023 14:00:0012345690
  • KerKol's avatar
    KerKol
    Icon for Power Participant rankPower Participant

    "field": "ScanEventTime",
    "type": "date"

     

    There's no field type of "date" it should be "temporal"

    Type | Vega-Lite

  • Adamboer's avatar
    Adamboer
    Icon for Responsive Resident rankResponsive Resident

    Hi,

    The error message "Invalid field type 'undefined'" typically means that there is a field in your data that has not been properly defined in your Vega-Lite code.

    In your case, it seems like the issue could be with the data type of your "ScanEventTime" column. The error message suggests that the data type is undefined. Double-check that the data type is correctly specified in your data source and ensure that it is being correctly referenced in your Vega-Lite code.

    Also, ensure that the values in your "ScanEventTime" column are valid date values. You may need to transform the data type or format the date values in a different way to make them compatible with Vega-Lite.

    Once you have resolved any data-related issues, try running your Vega-Lite code again to see if the error message persists. If you continue to encounter issues, consider posting a more detailed description of your data and code to a Vega-Lite forum or community group, where other users may be able to offer more specific guidance.