Snippets

Piotr Szrajber Smart M.App - manually tweak row chart's x axis properties

Created by Piotr Szrajber last modified
/**
 * Manually tweak row chart's properties using the dc.js API directly.
 * DC.js API docs can be found here: http://dc-js.github.io/dc.js/docs/html/dc.rowChart.html
 * 2017-0303 Piotr Szrajber <piotr.szrajber@hexagongeospatial.com>
 */
function setRowChartProperties() {
    // wait until thw widgets are rendered
    if (!document.querySelector(".bi-widget .widget-chart svg")) {
        setTimeout(setRowChartProperties, 500);
    }

    // gsp.ready("v1.0", function(gsp) { /* uncomment if using in browser's javascript console */
    // find all row charts
    gsp.bi.stage.findWidgets({
        descriptors: [{
            chartM: {
                chart: "row"
            }
        }]
    }, function(widgets) {
        var firstRowChart = widgets[0].chart;
        // prevent xAxis from dynamical rescaling
        firstRowChart.elasticX(false);
        // manually set x Axis properties
        firstRowChart.x(d3.scale.linear().range([0, 100]).domain([0, 100]));
        firstRowChart.xAxis().scale(firstRowChart.x());
        // manually set ticks
        firstRowChart.xAxis().ticks(4);
        firstRowChart.redraw();
    });
}

setRowChartProperties();

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.