简体   繁体   English

Vega-Lite 重复图表中的缩放、跟踪

[英]Zooming, Tracking in Vega-Lite repeated chart

Is there a way of getting interactivity into this vega-lite diagramm eg Zooming and Tracking like so https://vega.github.io/editor/#/edited , https://vega.github.io/vega-lite/examples/interactive_overview_detail.html Is there a way of getting interactivity into this vega-lite diagramm eg Zooming and Tracking like so https://vega.github.io/editor/#/edited , https://vega.github.io/vega-lite/examples /interactive_overview_detail.html

I tried for days now but nothing really works - either scaling is off or the combination of multilayer with interaction doesn't seem to work.我尝试了好几天,但没有任何效果 - 缩放关闭或多层与交互的组合似乎不起作用。 I need at least a way to zoom into the chart including tooltips...我至少需要一种方法来放大图表,包括工具提示......

    {
   "$schema":"https://vega.github.io/schema/vega-lite/v4.json",
   "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
         }
      ]
   },
   "repeat":{
      "layer":[
         "lowval",
         "highval",
         "resultdecimal"
      ]
   },
   "spec":{
      "mark":{
         "type":"line",
         "strokeWidth":3,
         "point":{
            "size":45,
            "filled":true
         }
      },
      "encoding":{
         "x":{
            "field":"serialnumber",
            "type":"ordinal",
            "axis":{
               "labelAngle":-70,
               "title":"Selected Tests",
               "titleFontSize":10
            }
         },
         "y":{
            "field":{
               "repeat":"layer"
            },
            "type":"quantitative",
            "axis":{
               "title":"Teststeps in selected Tests",
               "titleFontSize":10
            },
            "scale":{
               "domain":[
                  45000,
                  45500
               ]
            }
         },
         "tooltip":[
            {
               "field":"serialnumber",
               "type":"ordinal"
            },
            {
               "field":"resultdecimal",
               "type":"quantitative"
            }
         ],
         "color":{
            "datum":{
               "repeat":"layer"
            },
            "type":"nominal",
            "scale":{
               "range":[
                  "red",
                  "orange",
                  "blue",
                  "green"
               ]
            }
         }
      }
   },
   "config":{
      "font":"Roboto",
      "axisX":{
         "labelFontSize":9
      },
      "axisY":{
         "labelFontSize":9
      }
   }
}

No, zooming behavior is only available in Vega-Lite for quantitative axes, and your x-axis data is not quantitative (it consists of alphanumeric codes).不,缩放行为仅在 Vega-Lite 中可用于定量轴,并且您的 x 轴数据不是定量的(它由字母数字代码组成)。

Scale-bound selections also are not currently possible to use within repeated layers (I suspect this is a bug), so even if you transform your serial numbers to quantitative, you could not use a zoom directly.目前也无法在重复图层中使用比例限制选择(我怀疑这是一个错误),因此即使您将序列号转换为定量,也不能直接使用缩放。

One way to fix both these issues is to use transforms to convert your serial numbers to numeric, and to build your chart using fold rather than repeat ( view in editor ):解决这两个问题的一种方法是使用转换将序列号转换为数字,并使用fold而不是repeat构建图表( 在编辑器中查看):

{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "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
      }
    ]
  },
  "transform": [
    {
      "calculate": "parseInt(slice(datum.serialnumber, 2))",
      "as": "serialnumber"
    },
    {"fold": ["lowval", "highval", "resultdecimal"], "as": ["column", "value"]}
  ],
  "selection": {"zoom": {"type": "interval", "bind": "scales"}},
  "mark": {
    "type": "line",
    "strokeWidth": 3,
    "point": {"size": 45, "filled": true}
  },
  "encoding": {
    "x": {
      "field": "serialnumber",
      "type": "quantitative",
      "axis": {
        "labelAngle": -70,
        "title": "Selected Tests",
        "titleFontSize": 10
      }
    },
    "y": {
      "field": "value",
      "type": "quantitative",
      "axis": {"title": "Teststeps in selected Tests", "titleFontSize": 10},
      "scale": {"domain": [45000, 45500]}
    },
    "tooltip": [
      {"field": "serialnumber", "type": "ordinal"},
      {"field": "resultdecimal", "type": "quantitative"}
    ],
    "color": {
      "field": "column",
      "type": "nominal",
      "scale": {"range": ["red", "orange", "blue", "green"]}
    }
  },
  "config": {
    "font": "Roboto",
    "axisX": {"labelFontSize": 9},
    "axisY": {"labelFontSize": 9}
  }
}

在此处输入图像描述

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

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