Mohit
Mohit

Reputation: 461

Sorting issue in area chart of vegalite

I am try to create a chart using vconcat composition, i create a vconcat[0] as main chart and vconcat[1] for customize scroller , that bind with main chart to behave like a scroller. case first-issue is that xaxis label show that data is plot incorrectly , how i fix this. initially not rendering chart in a month series order Editor link Second case- when chart is initially render in a order but on using scroller (just drag mouse over the white strip to select area i.e vconca[1] and used that to move back and forth ) and then double click on scroller , chart is not comming with correct order month on X-axis label get mix not come in proper sequence of month and year as expected.chart initally render in sequence by adding sort null in x axis Editor link

i want chart properly come with sequence or as expected and view result correctly on using scroller back and fort and also show result properly of all data in a prope order when double click on the strip {vconcat[1]} means scroller always show correct data on scrolling and draging nad also on double click.

Upvotes: 1

Views: 75

Answers (1)

davidebacci
davidebacci

Reputation: 30304

Is this what you want?

enter image description here

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "values": [
      {"Count": 210.64, "month": "Jan-21", "name": "DRC"},
      {"Count": 179.95, "month": "Feb-21", "name": "WER"},
      {"Count": 155.48, "month": "Mar-21", "name": "GHJ"},
      {"Count": 230.72, "month": "Apr-21", "name": "THE"},
      {"Count": 167.27, "month": "May-21", "name": "JUY"},
      {"Count": 35.02, "month": "Jun-21", "name": "EDC"},
      {"Count": 234.97, "month": "Jul-21", "name": "QSD"},
      {"Count": 176.2, "month": "Aug-21", "name": "AXC"},
      {"Count": 163.84, "month": "Sep-21", "name": "FDS"},
      {"Count": 191.01, "month": "Oct-21", "name": "ASD"},
      {"Count": 182.99, "month": "Nov-21", "name": "THN"},
      {"Count": 119.79, "month": "Dec-21", "name": "RFV"},
      {"Count": 124.74, "month": "Jan-22", "name": "WSX"},
      {"Count": 241.88, "month": "Feb-22", "name": "QSA"},
      {"Count": 163.01, "month": "Mar-22", "name": "KOI"},
      {"Count": 137.3, "month": "Apr-22", "name": "YHN"},
      {"Count": 0, "month": "May-22", "name": "YHJ"},
      {"Count": 160.51, "month": "Jun-22", "name": "KLO"}
    ]
  },
  "transform": [{"window": [{"op": "row_number", "as": "row"}]}],
  "description": "Google's stock price over time.",
  "vconcat": [
    {
      "height": 250,
      "layer": [
        {
          "encoding": {
            "x": {
              "field": "month",
              "type": "nominal",
              "sort": {"field": "row", "order": "ascending"}
            },
            "y": {
              "field": "Count",
              "scale": {"zero": false},
              "type": "quantitative"
            }
          },
          "mark": {"line": true, "point": true, "tooltip": true, "type": "area"}
        }
      ],
      "transform": [{"filter": {"param": "brush"}}],
      "width": "container"
    },
    {
      "encoding": {
        "color": {"value": "lightGray"},
        "x": {
          "axis": {
            "labels": false,
            "ticks": false,
            "title": null
          },
          "field": "month",
          "type": "nominal",  "sort": {"field": "row", "order": "ascending"}
        },
        "y": {
          "field": "Count",
          "scale": {"zero": false},
          "type": "quantitative"
        }
      },
      "height": 40,
      "mark": {"opacity": 1, "type": "area"},
      "params": [
        {
          "name": "brush",
          "select": {"encodings": ["x"], "translate": true, "type": "interval"}
        }
      ],
      "width": "container"
    }
  ]
}

Upvotes: 1

Related Questions