Forum Discussion

JayWee's avatar
JayWee
Frequent Visitor
1 year ago
Solved

Unable to discretely split up dates

Hi All,

 

I'm having a tough time splitting up dates when using Deneb as i've just started using Power BI and Deneb not that long ago. 

 

The aim is to create something similar to what could be achieved in second image below using native Power BI line chart.

 

 

The code that i've tested thus far are:

 

 {
  "data": {
    "name": "dataset"
  },

  "layer": [

{"mark": {"type": "line", "point":true, 
 
"tooltip":true,
 "color":"#003668"},
"encoding": {



"x": {"field": "Date",
    "type": "temporal",
    "timeUnit": "datemonth",
    "axis": {"format":"%d/%m"},
    //"sort":["Point_ID","Date"],
    "scale":{"zero":false}

    
    },
"y":{"field":["Value"],
"type": "quantitative", 
"scale":{"zero":false},
"y2":{"field":["Point_ID"],
"type": "ordinal"}
}

}

}

  ]
}

I've posted on Stackoverflow since December last year but haven't heard a reply yet.

 

Please advice and Thanks in advance.

 

Jay

  • Hi JayWee ,

     

     

    Not an expert in Vega but I was able to do this using chat GPT:

     

    Preety similar.

    You need to  concatenate the axis to get this working:

    {
      "data": {
        "name": "dataset"
      },
      "transform": [
        {
          "calculate": "timeFormat(toDate(datum.Date), '%d/%m') + ' - ' + datum.Cat",
          "as": "DateCategory"
        }
      ],
      "mark": {
        "type": "line",
        "point": true,
        "tooltip": true
      },
      "encoding": {
        "x": {
          "field": "DateCategory",
          "type": "ordinal",
          "axis": {
            "title": "Date & Category",
            "labelAngle": -45
          }
        },
        "y": {
          "field": "Sum of Value",
          "type": "quantitative",
          "aggregate": "sum",
          "scale": {
            "zero": false
          }
        }
      }
    }

     

    Check the part of the code wher I do the transform of the axis.

     

     

     

3 Replies

  • Hi JayWee ,

     

     

    Not an expert in Vega but I was able to do this using chat GPT:

     

    Preety similar.

    You need to  concatenate the axis to get this working:

    {
      "data": {
        "name": "dataset"
      },
      "transform": [
        {
          "calculate": "timeFormat(toDate(datum.Date), '%d/%m') + ' - ' + datum.Cat",
          "as": "DateCategory"
        }
      ],
      "mark": {
        "type": "line",
        "point": true,
        "tooltip": true
      },
      "encoding": {
        "x": {
          "field": "DateCategory",
          "type": "ordinal",
          "axis": {
            "title": "Date & Category",
            "labelAngle": -45
          }
        },
        "y": {
          "field": "Sum of Value",
          "type": "quantitative",
          "aggregate": "sum",
          "scale": {
            "zero": false
          }
        }
      }
    }

     

    Check the part of the code wher I do the transform of the axis.

     

     

     

    • JayWee's avatar
      JayWee
      Frequent Visitor

      Thanks Miguel. That worked perfectly. Much appreciated.

      • MFelix's avatar
        MFelix
        Super User

        Full disclosure did it using some Google research and chat gpt.