admin管理员组

文章数量:1317905

I have a line chart with an errorband. Is it possible to limit the x-range of the errorband? In my case I would like the errorband to start at x=8 and end at x=17. I have tried a lot of combinations of scale, domain, range without success.

Also, can the calculate for y be written better, e.g. in three different parts?

{
  "params": [
    { "name": "band_max", "value": 2},
    { "name": "band_min", "value": -4}
  ],
  "data": {
    "sequence": {
      "start": 2,
      "stop": 20,
      "step": 1,
      "as": "x"
    }
  },
  "transform": [
    {
      "calculate": "datum.x<=10?0.5*datum.x+14:datum.x<=15?0.2*datum.x+17:0.5*datum.x+12.5",
      "as": "y"
    },
    { 
      "calculate": "band_max",
      "as": "y_band_max"
    },
    { 
      "calculate": "band_min",
      "as": "y_band_min"
    }
  ],
  "layer": [
    {
      "mark" : {
        "type" : "line"
      },
      "encoding": {
        "y": {
          "field": "y",
          "type": "quantitative",
          "scale": {"domain": [8, 30]}
        },
        "x": {
          "field": "x",
          "type": "quantitative"
        }
      }
    },
    {
      "mark": {
        "type": "errorband"
      },
      "encoding": {
        "y": {
          "field": "y",
          "type": "quantitative"
        },
        "yError": {"field": "y_band_max"},
        "yError2": {"field": "y_band_min"},
        "x": {
          "field": "x",
          "type": "quantitative"
        }        
      }
    }
  ]  
}

本文标签: vega liteLimit range for errorbandStack Overflow