【发布时间】:2021-09-23 09:52:33
【问题描述】:
我有这个代表某个数据集的小图表。正如您在代码 sn-p 中看到的,文本标签当前显示为与饼图组件本身相同的颜色,因此在位于饼图中时是不可见的(如果您更改,您可以看到这一点
mark: {type: "text", radius: 70},
到
mark: {type: "text", radius: 120},
因为文本标签将位于饼图弧的区域之外。因为我希望文本标签出现在弧内,所以我希望它们是黑色或白色的。有谁碰巧知道我如何实现这一目标?
vegaEmbed("#graph", {
$schema: "https://vega.github.io/schema/vega-lite/v5.json",
data: {
values: [{
event: "a",
occurances: 28,
},
{
event: "b",
occurances: 3,
},
{
event: "c",
occurances: 1,
},
{
event: "d",
occurances: 3,
},
{
event: "e",
occurances: 1,
},
{
event: "f",
occurances: 10,
},
{
event: "g",
occurances: 2,
},
{
event: "h",
occurances: 1,
},
{
event: "k",
occurances: 1,
},
],
},
layer: [{
mark: {
type: "arc",
innerRadius: 50,
outerRadius: 100
},
},
{
mark: {
type: "text",
radius: 70
},
encoding: {
text: {
field: "occurances",
type: "quantitive"
},
},
},
],
mark: {
type: "arc",
innerRadius: 50,
outerRadius: 100
},
encoding: {
color: {
field: "event",
type: "nominal",
},
theta: {
field: "occurances",
type: "quantitative",
stack: true,
},
},
});
<script src="https://cdn.jsdelivr.net/npm/vega@5"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-lite@5"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@6"></script>
<div id="graph"></div>
【问题讨论】:
标签: javascript html vega-lite vega