Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

119
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda