简体   繁体   English

Vega-lite 和/或 Vega 中是否可能出现迷你图?

[英]Are sparklines possible in Vega-lite and/or Vega?

Came across the following example using D3 yesterday...昨天遇到了以下使用 D3 的示例......

https://observablehq.com/@mbostock/covid-cases-by-state https://observablehq.com/@mbostock/covid-cases-by-state

Is this possible to be replicated in Vega-lite and/or Vega?这有可能在 Vega-lite 和/或 Vega 中复制吗?

You can have a look at the following example I was able to re-create: Vega-editor您可以查看我能够重新创建的以下示例: Vega-editor

Hope you are able to use it.希望你能够使用它。 Any feedback on how we can improve on this would be appreciated.任何关于我们如何改进这一点的反馈都将不胜感激。

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "url": "https://api.covidtracking.com/v1/states/daily.csv",
    "name": "dataset",
    "format": {"type": "csv"}
  },
  "facet": { 
    "row": {
      "field": "state",
      "sort": {
        "field": "positiveIncrease",
        "op": "average",
        "order": "descending"
      }
    }
  },
  "spec": {
    "transform": [
    {
      "calculate": "datetime(slice(datum.date,0,4), slice(datum.date,4,6),[slice(datum.date,6,8)])",
      "as": "__date"
    }
  ],
    "height": 20,
    "layer": [
      {
        "mark": {
          "type": "area"
        },
        "encoding": {
          "x": {
            "field": "__date",
            "type": "temporal",
            "timeUnit": "yearmonthdate",
            "axis": {
              "title": null,
              "orient": "top",
              "domain": false,
              "ticks": false,
              "labels": false,
              "grid": false
            }
          },
          "y": {
            "field": "positiveIncrease",
            "aggregate": "sum",
            "type": "quantitative",
            "axis": {
              "title": null,
              "domain": false,
              "labels": false,
              "ticks": false,
              "grid": false
            }
          }
        }
      },
      {
        "mark": {
          "type": "text",
          "align": "right",
          "dx": -120
        },
        "encoding": {
          "text": {
            "aggregate": {
              "argmax": "__date"
            },
            "field": "positiveIncrease",
            "format": ",.0f",
            "type": "quantitative"
          }
        }
      },
      {
        "mark": {
          "type": "text",
          "align": "right",
          "dx": -180
        },
        "encoding": {
          "text": {
            "aggregate": {
              "argmax": "__date"
            },
            "field": "positive",
            "format": ",.0f",
            "type": "quantitative"
          }
        }
      }
    ]
  },
  "resolve": {
    "scale": {"y": "independent"}
  },
  "config": {
  "view": {"stroke": "transparent"},
  "header": {
    "title": null,
    "labelAngle": 0,
    "labelAlign": "left",
    "labelFontSize": 12,
    "labelFont": "Arial"
  },
  "text": {
    "font": "Arial",
    "fontSize": 12
  },
  "facet": {"spacing": 1},
  "area":{
      "interpolate": "monotone",
          "line": {
            "color": "red",
            "strokeWidth": 1,
            "interpolate": "monotone"
          },
          "fill": "#faa"
  }
}

}

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

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