Vega,是否可以在 x 轴上有重复的标签

Vega, is it pssible to have duplicate labels in the x axis

我正在尝试使用 Vega 替换一些由 Google 图表 API 生成的图表。

这是一个包含 5 列的简单条形图,我之前使用 x 轴标签显示实际数字。

当我尝试使用 Vega 执行此操作时,它会将重复的数字合并到一列中。

这里是用于 vega 版本的 json(它或多或少是对快速入门示例的剪切和粘贴,其中数据值已更改)。

{
    "scales": [
        {
            "range": "width", 
            "type": "ordinal", 
            "name": "x", 
            "domain": {
                "field": "data.x", 
                "data": "table"
            }
        }, 
        {
            "range": "height", 
            "name": "y", 
            "domain": {
                "field": "data.y", 
                "data": "table"
            }, 
            "nice": true
        }
    ], 
    "axes": [
        {
            "scale": "x", 
            "type": "x"
        }, 
        {
            "scale": "y", 
            "type": "y", 
            "ticks": 3
        }
    ], 
    "height": 80, 
    "padding": {
        "top": 10, 
        "bottom": 20, 
        "right": 10, 
        "left": 30
    }, 
    "width": 200, 
    "marks": [
        {
            "from": {
                "data": "table"
            }, 
            "type": "rect", 
            "properties": {
                "hover": {
                    "fill": {
                        "value": "red"
                    }
                }, 
                "update": {
                    "fill": {
                        "value": "steelblue"
                    }
                }, 
                "enter": {
                    "y": {
                        "field": "data.y", 
                        "scale": "y"
                    }, 
                    "x": {
                        "field": "data.x", 
                        "scale": "x"
                    }, 
                    "y2": {
                        "scale": "y", 
                        "value": 0
                    }, 
                    "width": {
                        "band": true, 
                        "scale": "x", 
                        "offset": -1
                    }
                }
            }
        }
    ], 
    "data": [
        {
            "values": [ 
                { "y": 7,"x": 7 }, 
                { "y": 7,"x": 7 }, 
                { "y": 7,"x": 7 }, 
                { "y": 6,"x": 6 }, 
                { "y": 0,"x": 0 }, 
                { "y": 0,"x": 0 }
            ], 
            "name": "table"
        }
    ]
}

您应该确保 values 数组中的每个对象对于 x-axis 都有唯一的值。这是有道理的:否则,用户怎么知道每个栏指的是什么?如果您希望用相应的值标记每个条,那么您应该使用文本标记。请参阅 grouped bar 示例以获取指导。