Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
Rotating x-axis for bar chart with dc.js

I'm trying to rotate the x-axis label for my bar chart since if the names are too long, the labels overlap with each other. How do I rotate it at like 65 degrees so that it looks something like this.

I am using dc/d3.js with Angular and here is my code:

    let xAxis = data.key;
    let newData: any = [];

    for (let i = 0; i < xAxis.length; i++) {
        newData.push({
            'name': xAxis[i],
            'count': data.values[i]
        })
    }

    let ndx = crossfilter(newData);

    let nameDimension = ndx.dimension(function (d: any) {
        return d.name;
    });

    let countDimension: any = ndx.dimension(function (d: any) {
        return +d.count;
    });

    let countGroup = nameDimension.group().reduceSum(function (p: any) {
        return +p.count;
    });

    barChart
        .width(525)
        .height(450)
        .transitionDuration(1000) // Animation delay
        .margins({ top: 30, right: 50, bottom: 25, left: 40 })
        .dimension(nameDimension)
        .group(countGroup)
        .x(d3.scaleOrdinal().domain(xAxis))
        .xUnits(dc.units.ordinal)
        .y(d3.scaleLinear().domain([0, countDimension.top(1)[0].count * 1.1])) // Dynamic scale is 10% larger than max range
        .elasticY(false)
        .renderHorizontalGridLines(true)
        .colorAccessor(function (d: any, i: any) {
            return d3.schemePaired[i];
        })
        .ordinalColors(d3.schemePaired)
        .renderLabel(true)
        .label(function (p: any) {
            return p.y;
        });

    dc.renderAll(group);
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!