Vega Lite规范:尽管在规范中提供了数据,但显示为空图。

huangapple go评论92阅读模式
英文:

Vega lite spec Displaying an empty graph inspite of being provided with data in the spec

问题

Vega Lite规范显示一个空的图表,尽管规范中提供了数据。链接包含了正确的规范和空图表。我需要帮助找出错误在哪里。我尝试在Streamlit应用程序的一部分中显示此图表。我没有看到任何JavaScript或Python错误,只有一个空图表。

英文:

Vega lite spec showing an empty graph without any data points inspite of data being provided inside the spec. The link has the appropriate spec and empty graph. I need help in figuring out what the error is. I am trying to display this graph as part of a streamlit app. I am unable to see any javascript or python errors. Just an empty graph.

答案1

得分: 1

你需要转义字段名称中的句点。

{
  "description": "所有肿瘤试验的入组期限(以月为单位),使用不同颜色表示。",
  "data": {
    "values": [
      {"Trial": 0, "Enrollment_Duration_(Mos.)": 39.36},
      {"Trial": 1, "Enrollment_Duration_(Mos.)": 19.81},
      {"Trial": 2, "Enrollment_Duration_(Mos.)": 27.6},
      {"Trial": 3, "Enrollment_Duration_(Mos.)": 35.32},
      {"Trial": 4, "Enrollment_Duration_(Mos.)": 17.05},
      {"Trial": 6, "Enrollment_Duration_(Mos.)": 24.31},
      {"Trial": 7, "Enrollment_Duration_(Mos.)": 25.86},
      {"Trial": 8, "Enrollment_Duration_(Mos.)": 35.84},
      {"Trial": 9, "Enrollment_Duration_(Mos.)": 33.94},
      {"Trial": 10, "Enrollment_Duration_(Mos.)": 59.01},
      {"Trial": 11, "Enrollment_Duration_(Mos.)": 13.47},
      {"Trial": 12, "Enrollment_Duration_(Mos.)": 46.16},
      {"Trial": 14, "Enrollment_Duration_(Mos.)": 12.78},
      {"Trial": 16, "Enrollment_Duration_(Mos.)": 12.42},
      {"Trial": 17, "Enrollment_Duration_(Mos.)": 8.42},
      {"Trial": 18, "Enrollment_Duration_(Mos.)": 39.59},
      {"Trial": 19, "Enrollment_Duration_(Mos.)": 38.87},
      {"Trial": 20, "Enrollment_Duration_(Mos.)": 18.76},
      {"Trial": 21, "Enrollment_Duration_(Mos.)": 18.37},
      {"Trial": 23, "Enrollment_Duration_(Mos.)": 27.63},
      {"Trial": 24, "Enrollment_Duration_(Mos.)": 19.38},
      {"Trial": 26, "Enrollment_Duration_(Mos.)": 41.78},
      {"Trial": 27, "Enrollment_Duration_(Mos.)": 22.34},
      {"Trial": 28, "Enrollment_Duration_(Mos.)": 25.02},
      {"Trial": 29, "Enrollment_Duration_(Mos.)": 20.01},
      {"Trial": 31, "Enrollment_Duration_(Mos.)": 4.11},
      {"Trial": 32, "Enrollment_Duration_(Mos.)": 20.21},
      {"Trial": 33, "Enrollment_Duration_(Mos.)": 46},
      {"Trial": 34, "Enrollment_Duration_(Mos.)": 11.89}
    ]
  },
  "mark": "bar",
  "encoding": {
    "x": {
      "field": "Trial",
      "type": "ordinal",
      "axis": {"title": "肿瘤试验"}
    },
    "y": {
      "field": "Enrollment_Duration_(Mos\\.)",
      "type": "quantitative",
      "axis": {"title": "入组期限(月)"}
    },
    "color": {
      "field": "Trial",
      "type": "ordinal",
      "legend": {"title": "肿瘤试验"}
    }
  }
}
英文:

Vega Lite规范:尽管在规范中提供了数据,但显示为空图。

You need to escape full stops in your field names.

{
"description": "Enrollment duration (in months) of all Oncology Trials with different colors.",
"data": {
"values": [
{"Trial": 0, "Enrollment_Duration_(Mos.)": 39.36},
{"Trial": 1, "Enrollment_Duration_(Mos.)": 19.81},
{"Trial": 2, "Enrollment_Duration_(Mos.)": 27.6},
{"Trial": 3, "Enrollment_Duration_(Mos.)": 35.32},
{"Trial": 4, "Enrollment_Duration_(Mos.)": 17.05},
{"Trial": 6, "Enrollment_Duration_(Mos.)": 24.31},
{"Trial": 7, "Enrollment_Duration_(Mos.)": 25.86},
{"Trial": 8, "Enrollment_Duration_(Mos.)": 35.84},
{"Trial": 9, "Enrollment_Duration_(Mos.)": 33.94},
{"Trial": 10, "Enrollment_Duration_(Mos.)": 59.01},
{"Trial": 11, "Enrollment_Duration_(Mos.)": 13.47},
{"Trial": 12, "Enrollment_Duration_(Mos.)": 46.16},
{"Trial": 14, "Enrollment_Duration_(Mos.)": 12.78},
{"Trial": 16, "Enrollment_Duration_(Mos.)": 12.42},
{"Trial": 17, "Enrollment_Duration_(Mos.)": 8.42},
{"Trial": 18, "Enrollment_Duration_(Mos.)": 39.59},
{"Trial": 19, "Enrollment_Duration_(Mos.)": 38.87},
{"Trial": 20, "Enrollment_Duration_(Mos.)": 18.76},
{"Trial": 21, "Enrollment_Duration_(Mos.)": 18.37},
{"Trial": 23, "Enrollment_Duration_(Mos.)": 27.63},
{"Trial": 24, "Enrollment_Duration_(Mos.)": 19.38},
{"Trial": 26, "Enrollment_Duration_(Mos.)": 41.78},
{"Trial": 27, "Enrollment_Duration_(Mos.)": 22.34},
{"Trial": 28, "Enrollment_Duration_(Mos.)": 25.02},
{"Trial": 29, "Enrollment_Duration_(Mos.)": 20.01},
{"Trial": 31, "Enrollment_Duration_(Mos.)": 4.11},
{"Trial": 32, "Enrollment_Duration_(Mos.)": 20.21},
{"Trial": 33, "Enrollment_Duration_(Mos.)": 46},
{"Trial": 34, "Enrollment_Duration_(Mos.)": 11.89}
]
},
"mark": "bar",
"encoding": {
"x": {
"field": "Trial",
"type": "ordinal",
"axis": {"title": "Oncology Trials"}
},
"y": {
"field": "Enrollment_Duration_(Mos\\.)",
"type": "quantitative",
"axis": {"title": "Enrollment Duration (Months)"}
},
"color": {
"field": "Trial",
"type": "ordinal",
"legend": {"title": "Oncology Trials"}
}
}
}

huangapple
  • 本文由 发表于 2023年6月15日 20:43:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76482610.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定