0

enter image description here

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"
    }
  }
}
John
  • 23
  • 4

1 Answers1

0

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"}
      }
    }
Davide Bacci
  • 16,647
  • 3
  • 10
  • 36
  • thanks, I tried it just now and your suggestion makes x-axis more clearly, but y-axis always like that the pic upon, so I always find the way makes x-axis and y-axis display only 30 days nearly from now, but I get nothing event if I read most of offical doc of vega-lite – John Feb 01 '23 at 13:39
  • I know, but this pic from enough data, if I paste data into my code, it will explode, forgive me!! – John Feb 01 '23 at 13:44
  • Remove the labels from your plot. I'll update my answer. – Davide Bacci Feb 01 '23 at 13:51
  • sorry, I got you, but my request need to display the specific num in every spot, so I thought the best way is that reduce the data, but `cumulative_sum` aggs need all my data to guarantee the data integrity, so if you have any idea to display 30 days data from now by vega-lite DSL or reduce the returns data like parameter `size` after using `cumulative_sum` aggs, big thanks – John Feb 01 '23 at 14:03