Fix: Time Zone Format
This commit is contained in:
@@ -2,15 +2,15 @@ import { Box, CircularProgress, Alert } from '@mui/material';
|
|||||||
import type { CotizacionGanado } from '../models/mercadoModels';
|
import type { CotizacionGanado } from '../models/mercadoModels';
|
||||||
import { useApiData } from '../hooks/useApiData';
|
import { useApiData } from '../hooks/useApiData';
|
||||||
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts';
|
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts';
|
||||||
|
import { formatFullDateTime } from '../utils/formatters';
|
||||||
|
|
||||||
interface AgroHistoricalChartWidgetProps {
|
interface AgroHistoricalChartWidgetProps {
|
||||||
categoria: string;
|
categoria: string;
|
||||||
especificaciones: string;
|
especificaciones: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const formatXAxis = (tickItem: string) => {
|
const formatTooltipLabel = (label: string) => {
|
||||||
const date = new Date(tickItem);
|
return formatFullDateTime(label);
|
||||||
return date.toLocaleDateString('es-AR', { day: '2-digit', month: '2-digit' });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const AgroHistoricalChartWidget = ({ categoria, especificaciones }: AgroHistoricalChartWidgetProps) => {
|
export const AgroHistoricalChartWidget = ({ categoria, especificaciones }: AgroHistoricalChartWidgetProps) => {
|
||||||
@@ -29,13 +29,20 @@ export const AgroHistoricalChartWidget = ({ categoria, especificaciones }: AgroH
|
|||||||
return <Alert severity="info" sx={{ height: 300 }}>No hay suficientes datos históricos para graficar esta categoría.</Alert>;
|
return <Alert severity="info" sx={{ height: 300 }}>No hay suficientes datos históricos para graficar esta categoría.</Alert>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const formatXAxis = (tickItem: string) => {
|
||||||
|
return new Date(tickItem).toLocaleDateString('es-AR', { day: '2-digit', month: '2-digit' });
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ResponsiveContainer width="100%" height={300}>
|
<ResponsiveContainer width="100%" height={300}>
|
||||||
<LineChart data={data} margin={{ top: 5, right: 30, left: 20, bottom: 5 }}>
|
<LineChart data={data} margin={{ top: 5, right: 30, left: 20, bottom: 5 }}>
|
||||||
<CartesianGrid strokeDasharray="3 3" />
|
<CartesianGrid strokeDasharray="3 3" />
|
||||||
<XAxis dataKey="fechaRegistro" tickFormatter={formatXAxis} />
|
<XAxis dataKey="fechaRegistro" tickFormatter={formatXAxis} />
|
||||||
<YAxis domain={['dataMin - 10', 'dataMax + 10']} tickFormatter={(tick) => `$${tick.toLocaleString('es-AR')}`} />
|
<YAxis domain={['dataMin - 10', 'dataMax + 10']} tickFormatter={(tick) => `$${tick.toLocaleString('es-AR')}`} />
|
||||||
<Tooltip formatter={(value: number) => [`$${value.toFixed(2)}`, 'Precio Promedio']} />
|
<Tooltip
|
||||||
|
formatter={(value: number) => [`$${value.toFixed(2)}`, 'Precio Promedio']}
|
||||||
|
labelFormatter={formatTooltipLabel}
|
||||||
|
/>
|
||||||
<Legend />
|
<Legend />
|
||||||
<Line type="monotone" dataKey="promedio" name="Precio Promedio" stroke="#028fbe" strokeWidth={2} dot={false} />
|
<Line type="monotone" dataKey="promedio" name="Precio Promedio" stroke="#028fbe" strokeWidth={2} dot={false} />
|
||||||
</LineChart>
|
</LineChart>
|
||||||
|
|||||||
@@ -2,11 +2,16 @@ import { Box, CircularProgress, Alert } from '@mui/material';
|
|||||||
import type { CotizacionGrano } from '../models/mercadoModels';
|
import type { CotizacionGrano } from '../models/mercadoModels';
|
||||||
import { useApiData } from '../hooks/useApiData';
|
import { useApiData } from '../hooks/useApiData';
|
||||||
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts';
|
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts';
|
||||||
|
import { formatFullDateTime } from '../utils/formatters';
|
||||||
|
|
||||||
interface GrainsHistoricalChartWidgetProps {
|
interface GrainsHistoricalChartWidgetProps {
|
||||||
nombre: string;
|
nombre: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const formatTooltipLabel = (label: string) => {
|
||||||
|
return formatFullDateTime(label);
|
||||||
|
};
|
||||||
|
|
||||||
const formatXAxis = (tickItem: string) => {
|
const formatXAxis = (tickItem: string) => {
|
||||||
const date = new Date(tickItem);
|
const date = new Date(tickItem);
|
||||||
return date.toLocaleDateString('es-AR', { day: '2-digit', month: '2-digit' });
|
return date.toLocaleDateString('es-AR', { day: '2-digit', month: '2-digit' });
|
||||||
@@ -32,9 +37,13 @@ export const GrainsHistoricalChartWidget = ({ nombre }: GrainsHistoricalChartWid
|
|||||||
<ResponsiveContainer width="100%" height={300}>
|
<ResponsiveContainer width="100%" height={300}>
|
||||||
<LineChart data={data} margin={{ top: 5, right: 30, left: 20, bottom: 5 }}>
|
<LineChart data={data} margin={{ top: 5, right: 30, left: 20, bottom: 5 }}>
|
||||||
<CartesianGrid strokeDasharray="3 3" />
|
<CartesianGrid strokeDasharray="3 3" />
|
||||||
|
{/* Para los granos, usamos la fecha de operación en el eje X, que es más relevante */}
|
||||||
<XAxis dataKey="fechaOperacion" tickFormatter={formatXAxis} />
|
<XAxis dataKey="fechaOperacion" tickFormatter={formatXAxis} />
|
||||||
<YAxis domain={['dataMin - 1000', 'dataMax + 1000']} tickFormatter={(tick) => `$${tick.toLocaleString('es-AR')}`} />
|
<YAxis domain={['dataMin - 1000', 'dataMax + 1000']} tickFormatter={(tick) => `$${tick.toLocaleString('es-AR')}`} />
|
||||||
<Tooltip formatter={(value: number) => [`$${value.toFixed(0)}`, 'Precio']} />
|
<Tooltip
|
||||||
|
formatter={(value: number) => [`$${value.toFixed(0)}`, 'Precio']}
|
||||||
|
labelFormatter={formatTooltipLabel}
|
||||||
|
/>
|
||||||
<Legend />
|
<Legend />
|
||||||
<Line type="monotone" dataKey="precio" name="Precio" stroke="#028fbe" strokeWidth={2} dot={false} />
|
<Line type="monotone" dataKey="precio" name="Precio" stroke="#028fbe" strokeWidth={2} dot={false} />
|
||||||
</LineChart>
|
</LineChart>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Box, CircularProgress, Alert } from '@mui/material';
|
|||||||
import type { CotizacionBolsa } from '../models/mercadoModels';
|
import type { CotizacionBolsa } from '../models/mercadoModels';
|
||||||
import { useApiData } from '../hooks/useApiData';
|
import { useApiData } from '../hooks/useApiData';
|
||||||
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts';
|
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts';
|
||||||
|
import { formatFullDateTime } from '../utils/formatters';
|
||||||
|
|
||||||
interface HistoricalChartWidgetProps {
|
interface HistoricalChartWidgetProps {
|
||||||
ticker: string;
|
ticker: string;
|
||||||
@@ -9,10 +10,8 @@ interface HistoricalChartWidgetProps {
|
|||||||
dias: number;
|
dias: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Formateador para el eje X (muestra DD/MM)
|
const formatTooltipLabel = (label: string) => {
|
||||||
const formatXAxis = (tickItem: string) => {
|
return formatFullDateTime(label);
|
||||||
const date = new Date(tickItem);
|
|
||||||
return date.toLocaleDateString('es-AR', { day: '2-digit', month: '2-digit' });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const HistoricalChartWidget = ({ ticker, mercado, dias }: HistoricalChartWidgetProps) => {
|
export const HistoricalChartWidget = ({ ticker, mercado, dias }: HistoricalChartWidgetProps) => {
|
||||||
@@ -31,13 +30,21 @@ export const HistoricalChartWidget = ({ ticker, mercado, dias }: HistoricalChart
|
|||||||
return <Alert severity="info" sx={{height: 300}}>No hay suficientes datos históricos para graficar.</Alert>;
|
return <Alert severity="info" sx={{height: 300}}>No hay suficientes datos históricos para graficar.</Alert>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Formateador para el eje X que solo muestra día/mes
|
||||||
|
const formatXAxis = (tickItem: string) => {
|
||||||
|
return new Date(tickItem).toLocaleDateString('es-AR', { day: '2-digit', month: '2-digit' });
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ResponsiveContainer width="100%" height={300}>
|
<ResponsiveContainer width="100%" height={300}>
|
||||||
<LineChart data={data} margin={{ top: 5, right: 30, left: 20, bottom: 5 }}>
|
<LineChart data={data} margin={{ top: 5, right: 30, left: 20, bottom: 5 }}>
|
||||||
<CartesianGrid strokeDasharray="3 3" />
|
<CartesianGrid strokeDasharray="3 3" />
|
||||||
<XAxis dataKey="fechaRegistro" tickFormatter={formatXAxis} />
|
<XAxis dataKey="fechaRegistro" tickFormatter={formatXAxis} />
|
||||||
<YAxis domain={['dataMin - 1', 'dataMax + 1']} tickFormatter={(tick) => `$${tick.toLocaleString('es-AR')}`} />
|
<YAxis domain={['dataMin - 1', 'dataMax + 1']} tickFormatter={(tick) => `$${tick.toLocaleString('es-AR')}`} />
|
||||||
<Tooltip formatter={(value: number) => [`$${value.toFixed(2)}`, 'Precio']} />
|
<Tooltip
|
||||||
|
formatter={(value: number) => [`$${value.toFixed(2)}`, 'Precio']}
|
||||||
|
labelFormatter={formatTooltipLabel}
|
||||||
|
/>
|
||||||
<Legend />
|
<Legend />
|
||||||
<Line type="monotone" dataKey="precioActual" name="Precio de Cierre" stroke="#028fbe" strokeWidth={2} dot={false} />
|
<Line type="monotone" dataKey="precioActual" name="Precio de Cierre" stroke="#028fbe" strokeWidth={2} dot={false} />
|
||||||
</LineChart>
|
</LineChart>
|
||||||
|
|||||||
Reference in New Issue
Block a user