9951 explained code solutions for 126 technologies


javascript-d3How can I create a Qlik Sense Extension using D3.js?


Creating a Qlik Sense Extension using D3.js is relatively straightforward. It requires the following steps:

  1. Create a Qlik Sense Extension object using the Qlik Sense Extension API.
var extension = {
    definition: {
        type: "items",
        component: "accordion",
        items: {
            settings: {
                uses: "settings"
            }
        }
    },
    paint: function () {
        // This is where the D3.js code will go
    }
};
  1. Include the D3.js library in the extension.
<script src="https://d3js.org/d3.v5.min.js"></script>
  1. Write the D3.js code within the paint function of the extension.
paint: function () {
    var data = [4, 8, 15, 16, 23, 42];

    d3.select("#myChart")
        .selectAll("div")
        .data(data)
        .enter()
        .append("div")
        .style("height", function(d) {
            var barHeight = d * 5;
            return barHeight + "px";
        });
}
  1. Use the Qlik Sense Extension API to render the extension.
qlik.registerExtension("myExtension", extension);

The output of this code will be a bar chart rendered in the Qlik Sense app.

For more information, see the following links:

Edit this code on GitHub