Area Chart with Gradients in Power BI

Microsoft Power BI allows developers to use the declarative JSON syntax of the Vega or Vega-Lite languages to create highly customizable visuals. Vega and Vega-Lite are both languages for describing interactive data visualizations.

Here is the step-by-step guide for creating a custom visual in Power BI using the Deneb Vega-Lite.

  • Install the Deneb custom visual directly from Power BI. 
  • Open Power BI and create a new report. 
  • Click on the "Visualizations" pane on the screen. 
  • Click on the "Get more visuals" button. 
    Table and Matrix
  • Select "Deneb" from the list of custom visuals. 
    Visuals
  • Drag and drop the Deneb visual onto the report canvas. 
  • Click on the Deneb visual to select it. 
  • In the "Visualizations" pane, click on the "Fields" button to add data to the visual. 
  • Drag and drop the desired data fields onto the appropriate areas of the visual (e.g. "Values" for the y-axis, "Category" for the x-axis). 
    Edit
  • Customize the visual using the Deneb interface. This can include changing the chart type, adding titles and labels, and adjusting the color scheme. 
    Specification
{
  "data": {
    "name": "dataset"
  },
  "layer": [
    {
      "mark": {
        "type": "area",
        "opacity": 0.3,
        "tooltip": true
      },
      "encoding": {
        "y": {
          "field": "Sales"
        }
      }
    }
  ],
  "encoding": {
    "x": {
      "field": "Date",
      "type": "temporal"
    },
    "y": {
      "type": "quantitative",
      "axis": {
        "title": "Sales"
      }
    }
  }
}

Now we will start advanced configuration.

For the Tooltip

"tooltip": [
  {
    "field": "Dates",
    "type": "temporal"
  },
  {
    "field": "Sum of Price",
    "type": "quantitative"
  }
]

For gradient

"color": {
  "x1": 1,
  "y1": 1,
  "x2": 1,
  "y2": 0,
  "gradient": "linear",
  "stops": [
    {
      "offset": 0,
      "color": "#0C1228"
    },
    {
      "offset": 1,
      "color": "#118DFF"
    }
  ]
}

Format Axis label

"axis": {
    "labelAlign": "center",
    "labelExpr": "[timeFormat(datum.value, '%d ') + timeFormat(datum.value, '%b'), timeFormat(datum.value, '%m')   ? timeFormat(datum.value, '%Y') : '']"
}

Below are the sample images of the gradient Area Chart.

Gradient Area Chart

Power BI

Please note that the exact steps and options may change based on Power BI updates and the specific version you are using. Always refer to the latest Power BI documentation or resources for the most up-to-date information on creating custom Vega-Lite visualizations in Power BI.


Similar Articles