X-axis horizontal line and y-axis labels are not displaying in D3 Grouped bar chart

Asked
Active3 hr before
Viewed126 times

6 Answers

chartdisplayinghorizontal
90%

I am creating grouped bar chart using D3 V5 in react.I am able to display y axis but not ticks and text.but in case of x-axis it's completely invisible. i have added d3.min.js to index.html file, but nothing works. any help is appreciated, Is it safe to screw into a single support beam holding up an entire house? ,To learn more, see our tips on writing great answers.

Pretag
 Pretag team - issue, fix, solve, resolve
88%

Here is the code allowing to add a linear axis in a div that has the id res (html code not shown here).,Here is the Javascript code allowing to add a linear axis in a div that has the id 'res'.,Here is the Javascript code allowing to add a categoric axis in a div that has the id 'res'.

// create svg element
var svg = d3.select("#res")
   .append("svg")
   .attr("width", 1000)

// Create the scale
var x = d3.scaleLinear()
   .domain([0, 100]) // This is what is written on the Axis: from 0 to 100
   .range([100, 800]); // This is where the axis is placed: from 100px to 800px

// Draw the axis
svg
   .append("g")
   .attr("transform", "translate(0,50)") // This controls the vertical position of the Axis
   .call(d3.axisBottom(x));
load more v
72%

D3 provides the following functions to draw axes. , The axes renders human-readable reference marks for scales. Graphs have two axes: the horizontal axis or the x-axis and the vertical axis or the y-axis. , D3 provides functions to draw axes. An axis is made of lines, ticks and labels. An axis uses scale, so each axis will need to be given a scale to work with.

<body>
   <script>
      var width = 400,
         height = 100;

      var data = [10, 15, 20, 25, 30];

      // Append SVG 
      var svg = d3.select("body")
         .append("svg")
         .attr("width", width)
         .attr("height", height);

      // Create scale
      var scale = d3.scaleLinear()
         .domain([d3.min(data), d3.max(data)])
         .range([0, width - 100]);

      // Add scales to axis
      var x_axis = d3.axisBottom()
         .scale(scale);

      //Append group and insert axis
      svg.append("g")
         .call(x_axis);
   </script>
</body>
load more v
65%

Data points with wide differences in life expectancy would need to be further apart. ,.call() lets us separate the code for generating the axis from code that adds the axis to the graph. ,.orient() is used to specify the layout, such as whether the axis will be read at the top, bottom, left or right of the graph. The actual position is specified when the axis is drawn in later code.

load more v
75%

Start y-axis at 0 and not with the lowest value;,Add axis labels, title, source line.,Let’s go on with the axes of the chart. In order to draw the y-axis, I need to set the lowest and the highest value limit which in this case are 0 and 100.

Pretag
 Pretag team - issue, fix, solve, resolve
40%

bindto: '#myContainer'
// or element
bindto: document.getElementById('myContainer')
// or D3 selection object
bindto: d3.select('#myContainer')
load more v

Other "chart-displaying" queries related to "X-axis horizontal line and y-axis labels are not displaying in D3 Grouped bar chart"