Forum Discussion
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"
}
}
}
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
- giammariam
Solution Sage
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
Solution 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"}} }- yougainnothingFrequent Visitor
This has worked perfectly! Thank you so much, I think I can take it from here to where it needs to be.
- yougainnothingFrequent Visitor
giammariam I've seen you offer to help with Deneb bits before, I'm sorry if this is a very basic one
- giammariam
Solution Sage
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
- yougainnothingFrequent 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:34 12345678 07/02/2023 13:12:55 12345679 08/02/2023 10:10:10 12345680 08/02/2023 10:10:11 12345681 08/02/2023 10:23:11 12345682 08/02/2023 10:25:34 12345683 08/02/2023 10:59:12 12345684 09/02/2023 12:35:10 12345685 09/02/2023 12:36:46 12345686 09/02/2023 12:37:34 12345687 09/02/2023 13:40:10 12345688 09/02/2023 13:17:24 12345689 09/02/2023 14:00:00 12345690
- KerKol
Power Participant
"field": "ScanEventTime",
"type": "date"There's no field type of "date" it should be "temporal"
- Adamboer
Responsive 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.