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

113
Views
Chart.js two categorical scales

I have been trying to apply different datasets to a chart.js Chart but am having issues when I try to produce a plot with two categorical variables and make the scales categorical. Either all data is removed, or the x and y scales become mixed up/combined. I have mainly tried this with scatter plots as they should be able to visualize two categorical variables. Has anyone else experienced this issue or has a solution?

Preset/previously declared variables are:

dataset (object array), xdata (string), ydata (string)

My code is:

const myChart = new Chart(ctx, {

        type: "scatter",
        data: {
            datasets: [{
                display: false,
                data: dataset,
                pointBackgroundColor: ["#3e95cd"], // for scatter plot
            }],
            borderColor: "black",
        },
        options: {
            layout: {
                padding: 20,
            },
            parsing: {
                xAxisKey: xdata,
                yAxisKey: ydata,
            },
            responsive: false,
            scales: {
                y: {
                    display: true,
                    align: "center",
                    color: "black",
                    type: "category",
                    title: {
                        display: true,
                        text: ydata,
                        color: "black",
                        align: "center",
                        font: {
                            weight: "bold",
                        },
                    },
                },
                x: {
                    display: true,
                    align: "center",
                    color: "black",
                    type: "category",
                    title: {
                        display: true,
                        text: xdata,
                        color: "black",
                        align: "center",
                        font: {
                            weight: "bold",
                        },
                    },
                },
            },
            plugins: {
                title: {
                    display: true,
                    text: `Graph - ${ydata} vs ${xdata}`,
                    color: "black",
                    align: "center",
                    position: "top",
                    // This more specific font property overrides the global property
                    font: {
                        size: 16,
                        weight: "bold",
                    },
                },
                legend: {
                    display: false,
                },
            },

        },
    });
};

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

2 errors, type categorical does not exist. If you want a category axis you need to specify the type as: type:'category'. Also if you want a catergory Y axis you need to provide a labels array.

Also scatter plots don't display any category data by default. By default scatter plots have 2 linear axes.

about 4 years ago · Juan Pablo Isaza Report
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!