Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2.0 & D3.js don't apply Css on svg [duplicate]

I'm using Angular 2.0 TypeScript and d3.js libary for creating grafic. I'm trying to apply css on asix ( most importand shape-rendering: crispEdges; ). Do you have any idea?

here is the code

    var vis = d3.select("#visualisation"),
        WIDTH = 1000,
        HEIGHT = 500,
        MARGINS = {
            top: 20,
            right: 20,
            bottom: 20,
            left: 50
        },
        xRange = d3.scale.linear()
                   .range([MARGINS.left, WIDTH - MARGINS.right])
                   .domain([d3.min(this.calculationResults, function(d) { return d.time;}),
                             d3.max(this.calculationResults, function(d) { return d.time;})]),
        yRange = d3.scale.linear()
                    .range([HEIGHT - MARGINS.top, MARGINS.bottom])
                    .domain([d3.min(this.calculationResults, function(d) { return d.force; }),
                             d3.max(this.calculationResults, function(d) { return d.force;})]),
        xAxis = d3.svg.axis()
            .scale(xRange)
            .ticks(10)
            .tickSize(5)
           .tickSubdivide(true),
        yAxis = d3.svg.axis()
            .scale(yRange)
            .ticks(10)
            .tickSize(5)
            .orient("left")
            .tickSubdivide(true);

    vis.append("svg:g")
        .attr("class", "x axis")
        .attr("transform", "translate(0," + (HEIGHT - MARGINS.bottom) + ")")
        .call(xAxis);

    vis.append("svg:g")
        .attr("class", "y axis")
        .attr("transform", "translate(" + (MARGINS.left) + ",0)")
        .call(yAxis);

and css code

.axis path, .axis line
{
      fill: none;
      stroke: #777;
      shape-rendering: crispEdges; 
}
.tick
{
      stroke-dasharray: 1, 2;
}

please share your answer :)

like image 575
Lazar Krstic Avatar asked Apr 07 '16 11:04

Lazar Krstic


People also ask

Is Angular 2 and AngularJS same?

Angular 2 is a newer version of AngularJS, released in 2016. This version of the framework using TypeScript, which is an open-sourced programming language maintained by Microsoft. Angular 2 is more useful for developing mobile applications and includes higher performance speeds than AngularJS.

Is Angular 2 still supported?

Angular versions v2 to v11 are no longer under support.

Why is Angular 2 used?

Angular 2 is a framework for building web or mobile applications in HTML and Javascript or Typescript. It's the right choice of framework to use for your web or mobile applications.

What is the difference between Angular 2 and Angular 8?

Angular 2.0 is the older version and Angular 8.0 is the relatively newer version that has incorporated many new features. If you wish to get skilled in Angular, Angular rooting, TypeScript, Dependency Injection, Pipes, Forms, Bootstrap, System JS, etc.


1 Answers

I'm not sure but this should help you,

encapsulation mode

and/or

piercing CSS combinators >>>, /deep/ and ::shadow

look here - Styles in component for D3.js do not show in angular 2

Best luck !

like image 198
Nikhil Shah Avatar answered Sep 27 '22 20:09

Nikhil Shah