Forum Discussion

vivians's avatar
vivians
Frequent Visitor
1 year ago

Deneb chart with dynamic x-axis

Hi, I am trying to create a chart which is similar this Deneb chart with dynamic x-axis. I manage to change the x-axis into a dynamic axis, however, I can't change the size of the circle.

 

Here is my chart without dynamic x-axis:

and here is my chart with dynamic x-axis:

However, if I further remove the size of the circle, the chart will work fine with dynamic axis:

And here is my code for the Denab chart:

 

 

{
  "data": {
    "name": "dataset"
  },
  "transform": [
    {
      "joinaggregate": [
        {"op": "max", "field": "End of Month", "as": "max"},
        {"op": "min", "field": "Start of Month", "as": "min"}
      ]
    },
    {"calculate": "datum.max", "as": "max"},
    {"calculate": "datum.min", "as": "min"}
  ],
  "params": [
    {"name": "max", "expr": "data('data_0')[0]['max']"},
    {"name": "min", "expr": "data('data_0')[0]['min']"}
  ],  
"mark": {
        "type": "circle"
        },
      
  "encoding": {
    "x": {
      "field": "Date", 
      "timeUnit": "yearmonthdate",
      "type": "temporal",
      "scale": {"domain": {"expr": "[min,max]"}},
      
      "axis": {
        "tickCount": 10,
        "labelAlign": "left",
        "labelExpr": "[timeFormat(datum.value, '%b'), timeFormat(datum.value, '%m') == '01' ? timeFormat(datum.value, '%Y') : '']",
        "labelOffset": 4,
        "labelPadding": -24,
        "tickSize": 30,
        "gridDash": {
          "condition": {"test": {"field": "value", "timeUnit": "month", "equal": 1}, "value": []},
          "value": [2,2]
        },
        "tickDash": {
          "condition": {"test": {"field": "value", "timeUnit": "month", "equal": 1}, "value": []},
          "value": [2,2]
        }
      }
  },
    "y": {
      "field": "Country",
      "type": "nominal"
    },

    /*"size": {
      "field": "Point",
      "type": "quantitative",
      "aggregate": "sum",
      "legend": null
      
    },*/
    
    "color":{
      "field": "Type",
      "legend": null
    }
  }
}

 

 

Thank you very much!

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi vivians ,

     

    Not sure if it works.

    {
      "data": {
        "name": "dataset"
      },
      "transform": [
        {
          "joinaggregate": [
            {"op": "max", "field": "End of Month", "as": "max"},
            {"op": "min", "field": "Start of Month", "as": "min"}
          ]
        },
        {"calculate": "datum.max", "as": "max"},
        {"calculate": "datum.min", "as": "min"},
        
        // Now separately aggregate for size without affecting joinaggregate
        {
          "aggregate": [
            {"op": "sum", "field": "Point", "as": "sum_Point"}
          ],
          "groupby": ["Country", "Date"]  // Group by the required fields to avoid affecting X-axis
        }
      ],
      "params": [
        {"name": "max", "expr": "data('data_0')[0]['max']"},
        {"name": "min", "expr": "data('data_0')[0]['min']}
      ],  
      "mark": {
        "type": "circle"
      },
      "encoding": {
        "x": {
          "field": "Date", 
          "timeUnit": "yearmonthdate",
          "type": "temporal",
          "scale": {"domain": {"expr": "[min,max]"}},
          "axis": {
            "tickCount": 10,
            "labelAlign": "left",
            "labelExpr": "[timeFormat(datum.value, '%b'), timeFormat(datum.value, '%m') == '01' ? timeFormat(datum.value, '%Y') : '']",
            "labelOffset": 4,
            "labelPadding": -24,
            "tickSize": 30,
            "gridDash": {
              "condition": {"test": {"field": "value", "timeUnit": "month", "equal": 1}, "value": []},
              "value": [2, 2]
            },
            "tickDash": {
              "condition": {"test": {"field": "value", "timeUnit": "month", "equal": 1}, "value": []},
              "value": [2, 2]
            }
          }
        },
        "y": {
          "field": "Country",
          "type": "nominal"
        },
        "size": {
          "field": "sum_Point",  // Use the aggregated sum of Points for size
          "type": "quantitative",
          "legend": null
        },
        "color": {
          "field": "Type",
          "legend": null
        }
      }
    }
    

    If the problem persists, please consider posting it on the vega forum.

     

    Best Regards,

    Wearsky