简体   繁体   English

Vega-Lite 中的重新缩放图表

[英]Rescale Chart in Vega-Lite

We have this dataset which we want to visualize with Vega/Vega-Lite我们有这个数据集,我们想用 Vega/Vega-Lite 可视化

{
   "$schema":"https://vega.github.io/schema/vega-lite/v4.13.json",
   "description":"Testing",
   "width":"container",
   "height":350,
   "autosize":{
      "type":"fit",
      "contains":"padding"
   
},
   "layer":[
      {
         "data":{
            "values":[
               {
                  "stepid":"4444",
                  "stepname":"Name1",
                  "serialnumber":"SN3444444",
                  "lowval":45000,
                  "highval":45500,
                  "resultdecimal":45466
               
},
               {
                  "stepid":"4444",
                  "stepname":"Name1",
                  "serialnumber":"SN3444445",
                  "lowval":45000,
                  "highval":45500,
                  "resultdecimal":45433
               
},
               {
                  "stepid":"4444",
                  "stepname":"Name1",
                  "serialnumber":"SN3444446",
                  "lowval":45000,
                  "highval":45500,
                  "resultdecimal":45400
               
},
               {
                  "stepid":"4444",
                  "stepname":"Name1",
                  "serialnumber":"SN3444447",
                  "lowval":45000,
                  "highval":45500,
                  "resultdecimal":45422
               
},
               {
                  "stepid":"4444",
                  "stepname":"Name1",
                  "serialnumber":"SN3444448",
                  "lowval":45000,
                  "highval":45500,
                  "resultdecimal":45403
               
},
               {
                  "stepid":"4444",
                  "stepname":"Name1",
                  "serialnumber":"SN3444449",
                  "lowval":45000,
                  "highval":45500,
                  "resultdecimal":45422
               
}
            
]
         
},
         "layer":[
            {
               "mark":{
                  "type":"line",
                  "strokeWidth":3,
                  "point":{
                     "size":45,
                     "filled":true
                  
},
                  "interpolate":"monotone"
               
},
               "encoding":{
                  "x":{
                     "field":"serialnumber",
                     "type":"ordinal",
                     "axis":{
                        "labelAngle":-70,
                        "title":"Selected Tests",
                        "titleFontSize":10
                     
}
                  
},
                  "y":{
                     "field":"resultdecimal",
                     "type":"quantitative",
                     "axis":{
                        "title":"Teststeps in selected Tests",
                        "titleFontSize":10
                     
}
                  
},
                  "tooltip":[
                     {
                        "field":"serialnumber",
                        "type":"ordinal"
                     
},
                     {
                        "field":"resultdecimal",
                        "type":"quantitative"
                     
}
                  
]
               
}
            
},
            {
               "mark":"rule",
               "encoding":{
                  "y":{
                     "field":"highval"
                  
},
                  "stroke":{
                     "value":"#FF0000"
                  
}
               
}
            
},
            {
               "mark":"rule",
               "encoding":{
                  "y":{
                     "field":"lowval"
                  
},
                  "stroke":{
                     "value":"#FF0000"
                  
}
               
}
            
}
         
]
      
}
   
]
}

Everything works fine but the scaling on the y-axis is not too optimal一切正常,但 y 轴上的缩放比例不是太理想

在此处输入图像描述

Is it possible to rescale y-axis so it is more scaled-into-view based on lowval and highval eg like this one?是否可以重新缩放 y 轴,使其更基于 lowval 和 highval 缩放到视图中,例如像这个?

在此处输入图像描述

Furthermore is it possible to write the "lowval" and "highval" values on top of the lines?此外,是否可以在行的顶部写上“lowval”和“highval”值?

You can control the y-axis domain using the scale.domain property:您可以使用scale.domain属性控制 y 轴域:

"y": {
  "field": "resultdecimal",
  "type": "quantitative",
  "axis": {
    "title": "Teststeps in selected Tests",
    "titleFontSize": 10
  },
  "scale": {
    "domain": [45000, 45500]
  }
},

Adding that to your chart, results in this ( view in editor ):将其添加到您的图表中,结果如下( 在编辑器中查看): 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM