我尝试用机器制作停机时间饼图。我的输入是:
“值”:[{“Prostoj”:“1-5分钟”,“值”:10467,“textik”:“02:54:27”},
{"Prostoj": "5-12min", "value": 1470, "textik":"00:24:30"},
{"Prostoj": "12-35min", "value": 5100, "textik":"01:25:00"},
{"Prostoj": ">35min", "value": 1000, "textik":"00:00:00"}]
“Prostoj”是停机时间级别,“value”是以秒为单位的停机时间,“textik”是饼图的标签。我在 Vega-lite 中的代码是这样的:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "A simple pie chart with labels.",
"height":"container",
"width":"container",
"data": {
"values": [
{"Prostoj": "1-5min", "value": 10467, "textik":"02:54:27"},
{"Prostoj": "5-12min", "value": 1470, "textik":"00:24:30"},
{"Prostoj": "12-35min", "value": 5100, "textik":"01:25:00"},
{"Prostoj": ">35min", "value": 1000, "textik":"00:00:00"}
]
},
"encoding": {
"theta": {"field": "value", "type": "quantitative", "stack": true}
},
"layer": [{
"mark": {
"type": "arc",
"outerRadius": 150,
"padAngle":0.1,
"cornerRadius":10
},
"encoding": {
"color":{
"field":"Prostoj",
"type": "nominal",
"scale":{
"domain":["1-5min", "5-12min", "12-35min", ">35min"],
"range":["#00FFB9", "yellow", "orange", "red"]
},
"legend":null
}
}
}, {
"mark": {"type": "text", "radius": 100, "fontSize":12, "fontWeight":"bold"},
"encoding": {
"angle":{"value":0},
"theta":{"field":"value", "type": "quantitative", "stack":true},
"text": {"field": "Prostoj", "type": "nominal"}
}
}]
}
但是如果我选择“Prostoj”作为标签,则我有带有标签的问题,因为标签是正确位置的标签,但如果我选择标签变量“textik”,那么图表中的标签位置是错误的。有人可以帮助我吗? 提前非常感谢你。米罗斯拉夫
你的尺度相互矛盾,这令人困惑。这应该对你有用。
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "A simple pie chart with labels.",
"height":"container",
"width":"container",
"data": {
"values": [
{"Prostoj": "1-5min", "value": 10467, "textik":"02:54:27"},
{"Prostoj": "5-12min", "value": 1470, "textik":"00:24:30"},
{"Prostoj": "12-35min", "value": 5100, "textik":"01:25:00"},
{"Prostoj": ">35min", "value": 1000, "textik":"00:00:00"}
]
},
"encoding": {
"theta": {"field": "value", "type": "quantitative", "stack": true}
},
"layer": [{
"mark": {
"type": "arc",
"outerRadius": 150,
"padAngle":0.1,
"cornerRadius":10
},
"encoding": {
"color":{
"field":"Prostoj",
"type": "nominal",
"scale":{
"domain":["1-5min", "5-12min", "12-35min", ">35min"],
"range":["#00FFB9", "yellow", "orange", "red"]
},
"legend":null
}
}
}, {
"mark": {"type": "text", "radius": 100, "fontSize":12, "fontWeight":"bold"},
"encoding": {
"angle":{"value":0},
"theta":{"field":"value", "type": "quantitative", "stack":true},
"text": {"field": "Prostoj", "type": "nominal"}
}
}]
}