Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

  • 0
Pedroalves

problema com chart no angular

Pergunta

 

o problema é o seguinte eu criei um gráfico e agora quero buscar dados mas so consigo por a funcionar se por assim estou a usar o angular 7, nodejs e mongodb

let TotalSell = function() {
    var data = {
        labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
        datasets: [{
            label: 'My First dataset',
            fillColor: 'rgba(220,220,220,0.2)',
            strokeColor: 'rgba(220,220,220,1)',
            pointColor: 'rgba(220,220,220,1)',
            pointStrokeColor: '#fff',
            pointHighlightFill: '#fff',
            pointHighlightStroke: 'rgba(220,220,220,1)',
      data: [65, 59, 80, 81, 56, 55, 40, 84, 64, 120, 132, 87]
        }]
    };
var options = {

        maintainAspectRatio: false,

        // Sets the chart to be responsive
        responsive: true,

        ///Boolean - Whether grid lines are shown across the chart
        scaleShowGridLines: true,

        //String - Colour of the grid lines
        scaleGridLineColor: 'rgba(0,0,0,.05)',

        //Number - Width of the grid lines
        scaleGridLineWidth: 1,

        //Boolean - Whether the line is curved between points
        bezierCurve: false,

        //Number - Tension of the bezier curve between points
        bezierCurveTension: 0.4,

        //Boolean - Whether to show a dot for each point
        pointDot: true,

        //Number - Radius of each point dot in pixels
        pointDotRadius: 4,

        //Number - Pixel width of point dot stroke
        pointDotStrokeWidth: 1,

        //Number - amount extra to add to the radius to cater for hit detection outside the drawn point
        pointHitDetectionRadius: 20,

        //Boolean - Whether to show a stroke for datasets
        datasetStroke: true,

        //Number - Pixel width of dataset stroke
        datasetStrokeWidth: 2,

        //Boolean - Whether to fill the dataset with a colour
        datasetFill: true,

        // Function - on animation progress
        onAnimationProgress: function() {
        },

        // Function - on animation complete
        onAnimationComplete: function() {
        },

        //String - A legend template
        legendTemplate: '<ul class="tc-chart-js-legend"><% for (var i=0; i<datasets.length; i++){%><li><span style="background-color:<%=datasets[i].strokeColor%>"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>'
    };
    // Get context with jQuery - using jQuery's .get() method.
    var ctx = $("#TotalSell").get(0).getContext("2d");
    // This will get the first returned node in the jQuery collection.
    var chart1 = new Chart(ctx).Line(data, options);
    //generate the legend
    var legend = chart1.generateLegend();
    //and append it to your page somewhere
    $('#TotalSellLegend').append(legend);
};

<div class="col-sm-6">
            <h5 class="over-title margin-bottom-15" style="text-align:center;">Total Sell</h5>
            <canvas id="TotalSell" class="full-width"></canvas>
            <div class="margin-top-20">
              <div class="inline pull-left">
                <div id="TotalSellLegend" class="chart-legend"></div>
              </div>
            </div>
          </div>

o meu problema é como ponho a mostrar dados sem inserir dados aqui data: [65, 59, 80, 81, 56, 55, 40, 84, 64, 120, 132, 87] }] o meu objectivo é quando por a minha base de dados ele for buscar los a minha base de dados ou seja não quero ter que inserir manualmente no data:[] basicamente quero passar de dados staticos para dinamicos o que estou a fazer de errado

Compartilhar este post


Link para o post
Compartilhar em outros sites

0 respostas a esta questão

Recommended Posts

Até agora não há respostas para essa pergunta


  • Conteúdo Similar

    • Por belann
      Olá!
       
      Estou usando o editor quill em uma página html, sem fazer a instalação com npm, mas usando as api´s via internet com http, no entanto não consigo fazer a tecla enter funcionar para mudança de linha, tentei essa configuração abaixo, mas não funcionou.
       
      modules: {       syntax: true,       toolbar: '#toolbar-container',       keyboard: {         bindings: {           enter: {             key: 13,             handler: function(range, context) {                       quill.formatLine(range.index, range.length, { 'align': '' });             }           }  
       
    • Por belann
      Olá!
       
      Estou tentando iniciar uma Api de rotas no nodejs é da o seguinte erro:
      C:\Users\arifu\ntask-api\node_modules\consign\lib\consign.js:121
      /**
            ^
      Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\l\ntask-api\models\tasks.js from C:\Users\arifu\ntask-api\node_modules\consign\lib\consign.js not supported.
      tasks.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
      Instead either rename tasks.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in C:\Users\l\ntask-api\package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
          at Object.newLoader [as .js] (C:\Users\l\ntask-api\node_modules\pirates\lib\index.js:121:7)
          at Consign.into (C:\Users\l\ntask-api\node_modules\consign\lib\consign.js:231:15)
          at file:///C:/Users/l/ntask-api/index.js:11:3 {
        code: 'ERR_REQUIRE_ESM'
       
      Ja troquei type: module para type: commonjs e dá outros erros como na importação do express.
      package.json
       
      {   "name": "ntask-api",   "version": "1.0.0",   "description": "API de gestão de tarefas",   "main": "index.js",   "type": "module",   "scripts": {     "start": "babel-node index.js"   },   "author": "l",   "dependencies": {     "@babel/cli": "^7.0.0",     "@babel/core": "^7.0.0",     "@babel/preset-env": "^7.0.0",     "consign": "^0.1.2",     "express": "^4.18.2"   },   "devDependencies": {     "@babel/core": "^7.0.0",     "@babel/node": "^7.0.0",     "@babel/preset-env": "^7.23.3"   } }  
      index.js
      import express from 'express'; import consign from 'consign';   const app = express();   consign()  .include("models")  .then("libs/middlewares.js")  .then("routes")  .then("libs/boot.js")  .into(app);
    • Por belann
      Olá! 
      Não consigo iniciar um programa usando nodejs, babel e express
      npm start
      > nt-api@1.0.0 start
      > babel-node index.js
      C:\Users\ar\nt-api\node_modules\babel-core\lib\transformation\file\options\option-manager.js:328
              throw e;
              ^
      Error: Couldn't find preset "@babel/env" relative to directory "C:\\Users\\ar\\nt-api"
          at C:\Users\ar\nt-api\node_modules\babel-core\lib\transformation\file\options\option-manager.js:293:19
          at Array.map (<anonymous>)
          at OptionManager.resolvePresets (C:\Users\ar\nt-api\node_modules\babel-core\lib\transformation\file\options\option-manager.js:275:20)
          at OptionManager.mergePresets (C:\Users\ar\nt-api\node_modules\babel-core\lib\transformation\file\options\option-manager.js:264:10)
          at OptionManager.mergeOptions (C:\Users\ar\nt-api\node_modules\babel-core\lib\transformation\file\options\option-manager.js:249:14)
          at OptionManager.init (C:\Users\ar\nt-api\node_modules\babel-core\lib\transformation\file\options\option-manager.js:368:12)
          at compile (C:\Users\ar\nt-api\node_modules\babel-register\lib\node.js:103:45)
          at loader (C:\Users\ar\nt-api\node_modules\babel-register\lib\node.js:144:14)
          at Object.require.extensions.<computed> [as .js] (C:\Users\ar\nt-api\node_modules\babel-register\lib\node.js:154:7)
          at Module.load (node:internal/modules/cjs/loader:1207:32)
      Node.js v21.2.0
    • Por araujoitalo
      Olá a todos!
       
      Estou trabalhando em uma tabela utilizando a bilioteca ng2-smart-table e estou com uma dificuldade em passar para um componente customizado os valores inseridos na linha de edição:
       
      Veja o código abaixo, gostaria de passar para o componente SmartTableEditorFunctionsComponent os valores de Temperatura Máxima e Minima ao inserir uma nova linha na tabela.
      temperaturaMaxima: { type: 'number', title: 'Temperatura Máxima', }, temperaturaMinima: { title: 'Temperatura Mínima', type: 'number', }, temperaturaMedia: { title: 'Temperatura Média', type: 'number', editor: { type: 'custom', component: SmartTableEditorFunctionsComponent, valuePrepareFunction(instance) { instance.save.subscribe(); }, }, },  
      Imagem da tabela: 

       
      Criei um botão para tentar recuperar o valor, porem sem sucesso.
       
      Código do componente:
       
      export class SmartTableEditorFunctionsComponent extends DefaultEditor { @Input() value: string | number; @Input() rowData: any; @Output() save: EventEmitter<any> = new EventEmitter(); constructor() { super(); } getPlaceholder(value: any) { const id = value.column.temperaturaMaxima; return id; } test() { const id = this.rowData.temperaturaMaxima; alert('TESTE' + id); } } Código do template do componente: 
      {{ cell.newValue }} <input type="number" [(ngModel)]="cell.newValue" [name]="cell.getId()" [placeholder]="cell.getTitle()" [disabled]="!cell.isEditable()" (click)="onClick.emit($event)" /> <button (click)="test()">Pega Valor</button> Alguém poderia me ajudar?
    • Por araujoitalo
      Olá a todos!
       
      Estou trabalhando em uma tabela utilizando a bilioteca ng2-smart-table e estou com uma dificuldade em passar para um componente customizado os valores inseridos na linha de edição:
       
      Veja o código abaixo, gostaria de passar para o componente SmartTableEditorFunctionsComponent os valores de Temperatura Máxima e Minima ao inserir uma nova linha na tabela.
      temperaturaMaxima: { type: 'number', title: 'Temperatura Máxima', }, temperaturaMinima: { title: 'Temperatura Mínima', type: 'number', }, temperaturaMedia: { title: 'Temperatura Média', type: 'number', editor: { type: 'custom', component: SmartTableEditorFunctionsComponent, valuePrepareFunction(instance) { instance.save.subscribe(); }, }, },  
      Imagem da tabela: 

       
      Criei um botão para tentar recuperar o valor, porem sem sucesso.
       
      Código do componente:
       
      export class SmartTableEditorFunctionsComponent extends DefaultEditor { @Input() value: string | number; @Input() rowData: any; @Output() save: EventEmitter<any> = new EventEmitter(); constructor() { super(); } getPlaceholder(value: any) { const id = value.column.temperaturaMaxima; return id; } test() { const id = this.rowData.temperaturaMaxima; alert('TESTE' + id); } } Código do template do componente: 
      {{ cell.newValue }} <input type="number" [(ngModel)]="cell.newValue" [name]="cell.getId()" [placeholder]="cell.getTitle()" [disabled]="!cell.isEditable()" (click)="onClick.emit($event)" /> <button (click)="test()">Pega Valor</button> Alguém poderia me ajudar?
×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.