Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

115
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda