我正在尝试在 vegaLite 中创建一个具有双轴的图表。问题是,第二个 y 轴值是十进制的,如果我不使用第二个 y 轴的格式,那么它只是使用 4 位十进制数字进行格式。但我需要在点后最多 3 位小数。
如果我使用 format ("format":"0.3f") 那么它看起来像 y 轴上的重复值
我需要的所需视图仅在点后包含 3 个小数值并且不重复。
我根据动态数据值(字段最大值的 10% 额外。它是动态预先计算的)设置 maxDomain 第二个 y 轴值,而不使用 value:[] 。 怎么办??
您的domainMax不够大。当您的domainMax仅达到0.0011时,为什么您的域会显示0.002?
尝试添加tickCount并增加您的domainMax:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"background": {"expr": "BackgroundCanvasColor"},
"config": {
"axis": {
"labelFontStyle": {"expr": "AxisLabelFontStyle"},
"titleFontStyle": {"expr": "AxisTitleFontStyle"}
},
"font": {"expr": "FontType"},
"legend": {
"labelFontStyle": {"expr": "LegendLabelFontStyle"},
"labelLimit": {"expr": "LegendLabelLimit"},
"layout": {"top": {"anchor": "midivisionle"}},
"orient": {"expr": "LegendOrient"},
"symbolSize": {"expr": "LineLegendSymbolSize"},
"symbolType": {"expr": "LineLegendSymbol"}
},
"title": {
"fontStyle": {"expr": "TitleFontStyle"},
"subtitleFontStyle": {"expr": "SubtitleFontStyle"}
}
},
"data": {
"values": [
{"description_data": "ROW1", "division": 3, "subdivision": 0.001},
{"description_data": "ROW2", "division": 3, "subdivision": 0.001},
{"description_data": "ROW3", "division": 3, "subdivision": 0.001},
{"description_data": "ROW4", "division": 2, "subdivision": 0.001},
{"description_data": "ROW5", "division": 2, "subdivision": 0.001},
{"description_data": "ROW6", "division": 2, "subdivision": 0.001},
{"description_data": "ROW7", "division": 2, "subdivision": 0.001},
{"description_data": "ROW8", "division": 2, "subdivision": 0.001},
{"description_data": "ROW9", "division": 2, "subdivision": 0.001},
{"description_data": "ROW10", "division": 2, "subdivision": 0.001}
]
},
"params": [
{"name": "XAxisLabelAngle", "value": -45},
{"name": "YAxisLabelAngle", "value": 0},
{"name": "SubTitileColor", "value": "black"},
{"name": "TitleFontColor", "value": "black"},
{"name": "TitleFontSize", "value": 16},
{"name": "TitleAlign", "value": "center"},
{"name": "TitleText", "value": ""},
{"name": "TitleOrient", "value": "top"},
{"name": "TitleAnchor", "value": "midivisionle"},
{"name": "TitleBaseline", "value": "top"},
{"name": "TitleDx", "value": 0},
{"name": "SubtitleFont", "value": "bold"},
{"name": "TitleLimit", "value": 0},
{"name": "TitleOffset", "value": 5},
{"name": "Subtitle", "value": ""},
{"name": "SubtitleFontSize", "value": 16},
{"name": "MarkOpacity", "value": 1},
{"name": "XAxisPostion", "value": 0},
{"name": "YAxisPostion", "value": 0},
{"name": "YAxisTitle", "value": "division"},
{"name": "XAxisTitle", "value": "ROW"},
{"name": "YAxisLabelLimit", "value": 0},
{"name": "SecondYAxisLabelLimit", "value": 0},
{"name": "YAxisLabelSize", "value": 18},
{"name": "SecondYAxisLabelSize", "value": 17},
{"name": "XAxisLabelSize", "value": 17},
{"name": "XAxisLabelColor", "value": "black"},
{"name": "YAxisLabelColor", "value": "black"},
{"name": "SecondYAxisLabelColor", "value": "black"},
{"name": "XAxisTickSize", "value": 10},
{"name": "YAxisTickSize", "value": 10},
{"name": "SecondYAxisTickSize", "value": 4},
{"name": "BarLegendSymbolSize", "value": 0},
{"name": "LineLegendSymbolSize", "value": 0},
{"name": "YAxisTitleColor", "value": "black"},
{"name": "SecondYAxisTitleColor", "value": "black"},
{"name": "XAxisTitleColor", "value": "black"},
{"name": "YAxisTitleFontSize", "value": 18},
{"name": "SecondYAxisTitleFontSize", "value": 17},
{"name": "XAxisTitleFontSize", "value": 16},
{"name": "BarWidth", "value": 30},
{"name": "MarkShape", "value": "circle"},
{"name": "MarkShapeSize", "value": "50"},
{"name": "XAxisLabelLimit", "value": 0},
{"name": "YRangemax", "value": 3.3000000000000003},
{"name": "YRangemin", "value": null},
{"name": "SecondYRangemax", "value": 0.002},
{"name": "SecondYRangemin", "value": null},
{"name": "BarColor", "value": "#ffd4a3"},
{"name": "LineColor", "value": "#de3517"},
{"name": "PointInnerColor", "value": "#f54e24"},
{"name": "PointOuterColor", "value": "#f01919"},
{"name": "SecondYAxisTitle", "value": "SUB DIVISION VALUE"},
{"name": "LegendColumn", "value": 4},
{"name": "LegendLabelBaseline", "value": "midivisionle"},
{"name": "PointAngle", "value": 0},
{"name": "LegendLabelColor", "value": "#000000"},
{"name": "LegendLabelFontSize", "value": 14},
{"name": "LegendLabelLimit", "value": 0},
{"name": "LegendLabelOffset", "value": 25},
{"name": "LegendLabelOpicity", "value": "1"},
{"name": "LegendSymbolOpicity", "value": "0"},
{"name": "YAxisTitleX", "value": -40},
{"name": "BackgroundColor", "value": "#FFFFFF"},
{"name": "XAxisGridOpacity", "value": 0},
{"name": "YAxisGridOpacity", "value": 1},
{"name": "XAxisGridColor", "value": "#d3d3d3"},
{"name": "YAxisGridColor", "value": "#0d0c0c"},
{
"name": "BarLegendSymbol",
"value": "M1.75,1.5V1H0V.5H1.75V0h1.5V.5H5V1H3.25v.5Z"
},
{"name": "LineLegendSymbol", "value": "square"},
{"name": "LegendOrient", "value": "bottom"},
{"name": "FontType", "value": "Calibri"},
{"name": "TitleFontStyle", "value": "normal"},
{"name": "TitleFontWeight", "value": "normal"},
{"name": "SubtitleFontStyle", "value": "normal"},
{"name": "SubtitleFontWeight", "value": "normal"},
{"name": "AxisLabelFontStyle", "value": "bold"},
{"name": "AxisLabelFontWeight", "value": "normal"},
{"name": "AxisTitleFontStyle", "value": "bold"},
{"name": "AxisTitleFontWeight", "value": "normal"},
{"name": "LegendLabelFontStyle", "value": "normal"},
{"name": "BackgroundCanvasColor", "value": "#FFFFFF"}
],
"title": {
"align": {"expr": "TitleAlign"},
"anchor": {"expr": "TitleAnchor"},
"baseline": {"expr": "TitleBaseline"},
"color": {"expr": "TitleFontColor"},
"dx": {"expr": "TitleDx"},
"fontSize": {"expr": "TitleFontSize"},
"limit": {"expr": "TitleLimit"},
"offset": {"expr": "TitleOffset"},
"subtitle": {"expr": "Subtitle"},
"subtitleColor": {"expr": "SubTitileColor"},
"subtitleFontSize": {"expr": "SubtitleFontSize"},
"text": {"expr": "TitleText"}
},
"vconcat": [
{
"encoding": {
"scale": {"domain": {"param": "brush"}},
"sort": {"field": "id"},
"x": {
"axis": {
"grid": true,
"gridColor": {"expr": "XAxisGridColor"},
"gridOpacity": {"expr": "XAxisGridOpacity"},
"labelAngle": {"expr": "XAxisLabelAngle"},
"labelColor": {"expr": "XAxisLabelColor"},
"labelFontSize": {"expr": "XAxisLabelSize"},
"labelLimit": {"expr": "XAxisLabelLimit"},
"position": {"expr": "XAxisPostion"},
"tickSize": {"expr": "XAxisTickSize"},
"title": {"expr": "XAxisTitle"},
"titleColor": {"expr": "XAxisTitleColor"}
},
"field": "description_data",
"sort": {"field": "id"},
"type": "nominal"
}
},
"height": 200,
"layer": [
{
"encoding": {
"color": {
"datum": "",
"legend": {
"columns": {"expr": "LegendColumn"},
"labelBaseline": {"expr": "LegendLabelBaseline"},
"labelColor": {"expr": "LegendLabelColor"},
"labelFontSize": {"expr": "LegendLabelFontSize"},
"labelLimit": {"expr": "LegendLabelLimit"},
"labelOffset": {"expr": "LegendLabelOffset"},
"labelOpacity": {"expr": "LegendLabelOpicity"},
"orient": {"expr": "LegendOrient"},
"symbolOpacity": {"expr": "LegendSymbolOpicity"},
"symbolSize": {"expr": "BarLegendSymbolSize"},
"symbolType": {"expr": "BarLegendSymbol"}
},
"scale": {"range": [{"expr": "BarColor"}]}
},
"y": {
"axis": {
"gridColor": {"expr": "YAxisGridColor"},
"gridOpacity": {"expr": "YAxisGridOpacity"},
"labelAngle": {"expr": "YAxisLabelAngle"},
"labelColor": {"expr": "YAxisLabelColor"},
"labelFontSize": {"expr": "YAxisLabelSize"},
"labelLimit": {"expr": "YAxisLabelLimit"},
"position": {"expr": "YAxisPostion"},
"tickSize": {"expr": "YAxisTickSize"},
"title": {"expr": "YAxisTitle"},
"titleColor": {"expr": "YAxisTitleColor"},
"titleFontSize": {"expr": "YAxisTitleFontSize"},
"values": null
},
"field": "division",
"scale": {
"domainMax": {"expr": "YRangemax"},
"domainMin": {"expr": "YRangemin"},
"zero": false
},
"type": "quantitative"
}
},
"mark": {
"opacity": {"expr": "MarkOpacity"},
"tooltip": true,
"type": "bar",
"width": {"expr": "BarWidth"}
},
"params": [
{"name": "brush0", "select": {"encodings": ["x"], "type": "point"}}
]
},
{
"encoding": {
"color": {
"datum": "",
"legend": {"symbolStrokeColor": {"expr": "PointOuterColor"}},
"scale": {"range": [{"expr": "PointInnerColor"}]}
},
"y": {
"axis": {
"format": ".3f", "tickCount":2,
"grid": false,
"gridColor": {"expr": "YAxisGridColor"},
"gridOpacity": {"expr": "YAxisGridOpacity"},
"labelColor": {"expr": "SecondYAxisLabelColor"},
"labelFontSize": {"expr": "SecondYAxisLabelSize"},
"orient": "right",
"tickSize": {"expr": "SecondYAxisTickSize"},
"title": {"expr": "SecondYAxisTitle"},
"titleColor": {"expr": "SecondYAxisTitleColor"},
"titleFontSize": {"expr": "SecondYAxisTitleFontSize"}
},
"field": "subdivision",
"scale": {"domainMax": {"expr": "SecondYRangemax"}},
"sort": null,
"type": "quantitative"
}
},
"mark": {
"fill": "transparent",
"filled": true,
"point": {
"angle": {"expr": "PointAngle"},
"fill": {"expr": "PointInnerColor"},
"shape": {"expr": "MarkShape"},
"size": {"expr": "MarkShapeSize"},
"stroke": {"expr": "PointOuterColor"}
},
"stroke": {"expr": "LineColor"},
"tooltip": true,
"type": "line"
},
"params": [
{"name": "brush1", "select": {"encodings": ["x"], "type": "point"}}
]
}
],
"resolve": {
"scale": {
"color": "independent",
"shape": "independent",
"size": "independent",
"y": "independent"
}
},
"transform": [{"filter": {"param": "brush"}}],
"view": {"fill": {"expr": "BackgroundColor"}},
"width": "container"
},
{
"encoding": {
"color": {"value": "lightGray"},
"x": {
"axis": {"labels": false, "ticks": false, "title": ""},
"field": "description_data",
"sort": {"field": "id"},
"type": "nominal"
}
},
"height": 40,
"mark": {"opacity": 0, "type": "area"},
"params": [
{
"name": "brush",
"select": {"encodings": ["x"], "translate": true, "type": "interval"}
}
],
"width": "container"
}
],
"view": {"stroke": "transparent"}
}