简体   繁体   中英

The Vega-lite x-axis displays the specified number of data

在此处输入图像描述

Here is my generated pic, my x-axis is too large, so if I wanna display specified number, how can I fix my code?

I tried to cut my data source from ES DSL as my breakthrough point, but cumulative_sum needs complete data source.

{
  "$schema": "https://vega.github.io/schema/vega-lite/v2.json",
  "data": {
    "url": {
      "index": "x-*",
      "body": {
        "query": {"match_all": {}},
        "size": 0,
        "aggs": {
          "group_by_date": {
            "date_histogram": {
              "field": "timestamp",
              "interval": "day"
            },
            "aggs": {
              "cumulative_docs": {
                "cumulative_sum": {"buckets_path": "_count"}
              }
            }
          }
        }
      }
    },
    "format": {
      "property": "aggregations.group_by_date.buckets"
    }
  },
  "width": "container",
  "height": 1200,
  "layer": [
    {
    "mark": {
        "type": "line",
        "point": {"filled": false, "fill": "black"}
      }
    },
    {
      "mark": {
        "type": "text",
        "align": "left",
        "baseline": "middle",
        "fontSize": 15
      },
      "encoding": {
        "text": {"field": "cumulative_docs.value", "type": "quantitative"}
      }
    }
  ],
  "encoding": {
    "x": {
      "axis": {"title": "date"},
      "field": "key_as_string",
      "type": "nominal"
    },
    "y": {
      "aggregate": "y",
      "axis": {"title": "project_num"},
      "field": "cumulative_docs.value",
      "type": "quantitative",
      "stack": "normalize"
    }
  }
}

It is difficult to debug without actual data but what happens if you change this to temporal?

"x": {
      "axis": {"title": "date"},
      "field": "key_as_string",
      "type": "temporal"
    },

EDIT

Remove this section.

{
      "mark": {
        "type": "text",
        "align": "left",
        "baseline": "middle",
        "fontSize": 15
      },
      "encoding": {
        "text": {"field": "cumulative_docs.value", "type": "quantitative"}
      }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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