Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Vega Lite – can I anchor a horizontal line with only values of 0 to the bottom of the chart instead of the middle?

I’m trying to get a chart to look nicer in Vega-Lite. If I have multiple points all at a value of 0 the line is centered in the chart.

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",

  "data": {
    "values": [
      { "date": "2022-07-27 4:20", "value": 0 },
      { "date": "2022-07-27 4:21", "value": 0 },
      { "date": "2022-07-27 4:22", "value": 0 },
      { "date": "2022-07-27 4:23", "value": 0 },
      { "date": "2022-07-27 4:24", "value": 0 },
      { "date": "2022-07-27 4:25", "value": 0 },
      { "date": "2022-07-27 4:26", "value": 0 },
      { "date": "2022-07-27 4:27", "value": 0 },
      { "date": "2022-07-27 4:28", "value": 0 },
      { "date": "2022-07-27 4:29", "value": 0 },
      { "date": "2022-07-27 4:30", "value": 0 },
      { "date": "2022-07-27 4:31", "value": 0 },
      { "date": "2022-07-27 4:32", "value": 0 },
      { "date": "2022-07-27 4:33", "value": 0 },
      { "date": "2022-07-27 4:34", "value": 0 },
      { "date": "2022-07-27 4:35", "value": 0 },
      { "date": "2022-07-27 4:36", "value": 0 },
      { "date": "2022-07-27 4:37", "value": 0 },
      { "date": "2022-07-27 4:38", "value": 0 },
      { "date": "2022-07-27 4:39", "value": 0 }
    ]
  },

  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },

    "y": {
      "field": "value",
      "type": "quantitative"
    }
  },

  "mark": {
    "type": "line"
  }

}

rendered chart

Is there a way to get the line to be anchored to the bottom instead?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Set a domain.

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",

  "data": {
    "values": [
      { "date": "2022-07-27 4:20", "value": 0 },
      { "date": "2022-07-27 4:21", "value": 0 },
      { "date": "2022-07-27 4:22", "value": 0 },
      { "date": "2022-07-27 4:23", "value": 0 },
      { "date": "2022-07-27 4:24", "value": 0 },
      { "date": "2022-07-27 4:25", "value": 0 },
      { "date": "2022-07-27 4:26", "value": 0 },
      { "date": "2022-07-27 4:27", "value": 0 },
      { "date": "2022-07-27 4:28", "value": 0 },
      { "date": "2022-07-27 4:29", "value": 0 },
      { "date": "2022-07-27 4:30", "value": 0 },
      { "date": "2022-07-27 4:31", "value": 0 },
      { "date": "2022-07-27 4:32", "value": 0 },
      { "date": "2022-07-27 4:33", "value": 0 },
      { "date": "2022-07-27 4:34", "value": 0 },
      { "date": "2022-07-27 4:35", "value": 0 },
      { "date": "2022-07-27 4:36", "value": 0 },
      { "date": "2022-07-27 4:37", "value": 0 },
      { "date": "2022-07-27 4:38", "value": 0 },
      { "date": "2022-07-27 4:39", "value": 0 }
    ]
  },

  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },

    "y": {
      "field": "value", "scale":{"domain":[0,1]},
      "type": "quantitative"
    }
  },

  "mark": {
    "type": "line"
  }

}

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading