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

658
Visualizações
error: Uncaught TypeError: Illegal constructor JavaScript
const cases = document.querySelector('coronovirus-input');
const deaths = document.querySelector('deaths-input');
const recovered =document.querySelector('recovered-input');

const ctx = document.getElementById('mychart').getContext("2d");
let mychart = new CharacterData(ctx , {

  type:'pie',
  data: {
    labels : ['Active Cases','Deaths','Recovered'],
    datasets : [
      {
        label:'# of votes',
        data : [0,0,0],
        backgroundColor:['#2adece','#dd3b79','#ff766b'],
        borderWidth:1
      }
    ]
    
  }
});

const updateChartValue = (input, dataOrder) => {

  input.addEventListener ('change', e => {
    mychart.data.datasets[0].data[DataOrder] = e.target.value;
    mychart.update();
  });

};

updateChartValue(cases,0);
updateChartValue(deaths,1);
updateChartValue(recovered,2);

Hi Guys I cant solve this problem... i want to make pie chart but I cant I am newbie to share any post in this website sorry if I did any mistakes This Error

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I see several issues in the code you posted, but most notably the constructor for initialising mychart should be new Chart() rather than new CharacterData() (possible typo due to auto-completion in your editor?).

Second, mind that selectors for element ids must be prefixed with #.

Finally the updateChartValue shows a mismatch in the case of the dataOrder argument and where it is used (capital 'D').

See solution here https://codepen.io/beezital/pen/zYEmKRG

const cases = document.querySelector('#coronovirus-input');
const deaths = document.querySelector('#deaths-input');
const recovered =document.querySelector('#recovered-input');

const ctx = document.getElementById('mychart').getContext("2d");
let mychart = new Chart(ctx , {

  type:'pie',
  data: {
    labels : ['Active Cases','Deaths','Recovered'],
    datasets : [
      {
        label:'# of votes',
        data : [10,20,30],
        backgroundColor:['#2adece','#dd3b79','#ff766b'],
        borderWidth:1
      }
    ]
    
  }
});

const updateChartValue = (input, dataOrder) => {

  input.addEventListener ('change', e => {
    mychart.data.datasets[0].data[dataOrder] = e.target.value;
    mychart.update();
  });

};

updateChartValue(cases,0);
updateChartValue(deaths,1);
updateChartValue(recovered,2);
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