Guest User

Untitled

a guest
Jul 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. import { Component, ViewChild, OnInit } from '@angular/core';
  2. import { NavController } from 'ionic-angular';
  3. import { Chart } from 'chart.js';
  4.  
  5. @Component({
  6. selector: 'page-home',
  7. templateUrl: 'home.html'
  8. })
  9. export class HomePage implements OnInit {
  10. @ViewChild('lineCanvas') lineCanvas;
  11. lineChart: any;
  12. etiquetas = [];
  13. valores = [];
  14. funcion = '';
  15. constructor(public navCtrl: NavController) {
  16.  
  17. }
  18.  
  19. ngOnInit() {
  20. this.derivada();
  21.  
  22. }
  23.  
  24. calcular() {
  25. this.funcion = 'Sin(x)';
  26. let fx= 0;
  27. for(let i = 0; i<=360 ; i++){
  28. this.etiquetas.push(i.toString());
  29. fx= Math.sin(i*Math.PI/180);
  30. this.valores.push(fx);
  31. }
  32. }
  33.  
  34. derivada() {
  35. this.funcion = 'd(Sin(x))/dx';
  36. const h = 0.0000001;
  37. let fx = 0;
  38. for(let i = 0; i<=360 ; i++){
  39. this.etiquetas.push(i.toString());
  40. fx = Math.sin(i*Math.PI/180);
  41. let fxMASh = Math.sin(i*Math.PI/180 + h);
  42. let Derivada = (fxMASh - fx)/h;
  43. this.valores.push(Derivada);
  44. }
  45. }
  46.  
  47. graficar() {
  48. this.lineChart = new Chart(this.lineCanvas.nativeElement, {
  49. type: 'line',
  50. data: {
  51. labels: this.etiquetas,
  52. datasets: [
  53. {
  54. label: this.funcion,
  55. fill: false,
  56. lineTension: 0,
  57. backgroundColor: "rgba(0,0,255,0.5)",
  58. borderColor: "rgba(0,0,255,0.5)",
  59. borderCapStyle: 'butt',
  60. borderDash: [],
  61. borderDashOffset: 0.0,
  62. borderJoinStyle: 'miter',
  63. pointBorderColor: "rgba(255,0,0,1)",
  64. pointBackgroundColor: "#fff",
  65. pointBorderWidth: 1,
  66. pointHoverRadius: 5,
  67. pointHoverBackgroundColor: "rgba(0,255,0,1)",
  68. pointHoverBorderColor: "rgba(255,0,0,1)",
  69. pointHoverBorderWidth: 2,
  70. pointRadius: 2,
  71. pointHitRadius: 10,
  72. data: this.valores,
  73. spanGaps: false,
  74. }
  75. ]
  76. }
  77. });
  78. }
  79. }
Add Comment
Please, Sign In to add comment