Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Background color as gradient in stacked area chart #758

Open
reachtoakhtar opened this issue Dec 3, 2018 · 1 comment
Open

Background color as gradient in stacked area chart #758

reachtoakhtar opened this issue Dec 3, 2018 · 1 comment

Comments

@reachtoakhtar
Copy link

I want to use the background colour as gradient in stacked area chart. Is it possible?

@reachtoakhtar
Copy link
Author

reachtoakhtar commented Dec 4, 2018

Found a workaround. Insert a linearGradient element inside svg by using the callback attribute in chart and apply the following css:

.nv-area {
  fill: url(#grad3) !important;
}
chart: {
    type: 'stackedAreaChart', 
    height: 350,
    ...
    ...
    callback: function (chart) {

        // Add gradient color to graph.
        var linearGrad = d3.select("svg").append("linearGradient");
        linearGrad.attr('id', 'grad3');
        linearGrad.attr("x1", "0%");
        linearGrad.attr("x2", "100%");
        linearGrad.attr("y1", "0%");
        linearGrad.attr("y2", "100%");
        linearGrad.html(
            '<stop offset="0%" style="stop-color:rgb(255,255,0);stop-opacity:1"/>' +
            '<stop offset="100%" style="stop-color:rgb(255,0,0);stop-opacity:1"/>'
        );
    }
}

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant