|
1 | | -import { Doughnut } from 'react-chartjs-2'; |
2 | | -import { Chart as ChartJS, ArcElement, Tooltip, Legend } from 'chart.js'; |
| 1 | +import { Doughnut } from "react-chartjs-2"; |
| 2 | +import { Chart as ChartJS, ArcElement, Tooltip, Legend } from "chart.js"; |
3 | 3 |
|
4 | 4 | ChartJS.register(ArcElement, Tooltip, Legend); |
5 | 5 |
|
6 | | -const productosStock = [ |
7 | | - { nombre: 'Botón Z6', cantidad: 500 }, |
8 | | - { nombre: 'Botón R4', cantidad: 300 }, |
9 | | - { nombre: 'Botón L2', cantidad: 200 }, |
10 | | - { nombre: 'Botón M1', cantidad: 100 }, |
11 | | - { nombre: 'Botón N8', cantidad: 50 }, |
12 | | -]; |
| 6 | +const colores = ["#4ade80", "#60a5fa", "#facc15", "#fb923c", "#f87171"]; |
13 | 7 |
|
14 | | -const colores = ['#4ade80', '#60a5fa', '#facc15', '#fb923c', '#f87171']; |
15 | | - |
16 | | -const data = { |
17 | | - labels: productosStock.map(p => p.nombre), |
18 | | - datasets: [ |
19 | | - { |
20 | | - data: productosStock.map(p => p.cantidad), |
21 | | - backgroundColor: colores, |
22 | | - borderWidth: 1, |
23 | | - }, |
24 | | - ], |
25 | | -}; |
| 8 | +export default function StockActualProductosBL({ productosStock }) { |
| 9 | + // console.log(productosStock); |
| 10 | + const productosStockArray = Object.values(productosStock); |
| 11 | + const data = { |
| 12 | + labels: productosStockArray.map((p) => p.descripcion), |
| 13 | + datasets: [ |
| 14 | + { |
| 15 | + data: productosStockArray.map((p) => p.stock_total), |
| 16 | + backgroundColor: colores, |
| 17 | + borderWidth: 1, |
| 18 | + }, |
| 19 | + ], |
| 20 | + }; |
26 | 21 |
|
27 | | -const options = { |
28 | | - responsive: true, |
29 | | - maintainAspectRatio: false, |
30 | | - cutout: '70%', |
31 | | - plugins: { |
32 | | - legend: { |
33 | | - position: 'bottom', |
34 | | - labels: { |
35 | | - boxWidth: 12, |
36 | | - font: { |
37 | | - size: 10, |
| 22 | + const options = { |
| 23 | + responsive: true, |
| 24 | + maintainAspectRatio: false, |
| 25 | + cutout: "70%", |
| 26 | + plugins: { |
| 27 | + legend: { |
| 28 | + position: "bottom", |
| 29 | + labels: { |
| 30 | + boxWidth: 12, |
| 31 | + font: { size: 10 }, |
| 32 | + color: "#374151", |
38 | 33 | }, |
39 | | - color: '#374151', |
40 | 34 | }, |
41 | 35 | }, |
42 | | - }, |
43 | | -}; |
| 36 | + }; |
44 | 37 |
|
45 | | -export default function StockActualProductosBL() { |
46 | 38 | return ( |
47 | 39 | <div className="relative flex flex-col h-full p-4"> |
48 | 40 | <h3 className="text-base font-semibold text-gray-900 dark:text-white mb-3"> |
|
0 commit comments