import React, { useEffect, useState } from 'react'; import { Rnd } from 'react-rnd';…
- User
import React, { useEffect, useState } from 'react'; import { Rnd } from 'react-rnd'; import Highcharts from 'highcharts/highstock'; import HighchartsReact from 'highcharts-react-official'; import IndicatorsAll from 'highcharts/indicators/indicators-all'; import { Box, Button, IconButton, Typography, Paper, Grid, } from '@mui/material'; import CloseIcon from '@mui/icons-material/Close'; import IndicatorSelector from './IndicatorSelector';
if (typeof Highcharts === 'object') { IndicatorsAll(Highcharts); }
interface ChartOverlayProps { data: any[]; symbol: string; selectedPreset: string | null; onClose: () => void; onPresetChange: (preset: string) => void; startDate: Date; endDate: Date; }
const ChartOverlay: React.FC = ({ data, symbol, selectedPreset, onClose, onPresetChange, startDate, endDate, }) => { const [position, setPosition] = useState({ x: 100, y: 100 }); const [size, setSize] = useState({ width: 800, height: 600 }); const [chartOptions, setChartOptions] = useState<Highcharts.Options>({});
useEffect(() => { const savedPosition = localStorage.getItem('chartPosition'); const savedSize = localStorage.getItem('chartSize');
if (savedPosition) { setPosition(JSON.parse(savedPosition)); } if (savedSize) { setSize(JSON.parse(savedSize)); } updateChartOptions();}, [data, symbol, startDate, endDate]);
const handleDragStop = (e: any, d: any) => { setPosition({ x: d.x, y: d.y }); localStorage.setItem('chartPosition', JSON.stringify({ x: d.x, y: d.y })); };
const handleResizeStop = (e: any, direction: any, ref: any, delta: any, position: any) => { setSize({ width: ref.style.width, height: ref.style.height }); setPosition(position); localStorage.setItem('chartSize', JSON.stringify({ width: ref.style.width, height: ref.style.height })); localStorage.setItem('chartPosition', JSON.stringify(position)); };
const updateChartOptions = () => { const newOptions: Highcharts.Options = { chart: { animation: { duration: 500 }, }, title: { text: ${symbol} Price Chart, }, rangeSelector: { selected: 2, // Default to 3M buttons: [{ type: 'month', count: 1, text: '1M' }, { type: 'month', count: 3, text: '3M' }, { type: 'month', count: 6, text: '6M' }, { type: 'ytd', text: 'YTD' }, { type: 'year', count: 1, text: '1Y' }, { type: 'all', text: 'All' }] }, navigator: { adaptToUpdatedData: true, series: { data: data } }, xAxis: { type: 'datetime', ordinal: false, }, yAxis: [{ title: { text: 'Price', }, height: '60%', }, { title: { text: 'Volume', }, top: '65%', height: '35%', offset: 0, }], series: [{ type: 'candlestick', id: 'mainSeries', name: symbol, data: data.map(item => [ new Date(item.date).getTime(), item.open, item.high, item.low, item.close ]), connectNulls: true }, { type: 'column', id: 'volume', name: 'Volume', data: data.map(item => [ new Date(item.date).getTime(), item.volume ]), yAxis: 1, }], };
setChartOptions(newOptions); };
const handleApplyIndicator = (indicatorName: string, params: Record<string, number>) => { console.log('Applying indicator:', indicatorName, params); const newOptions = { ...chartOptions };
- Assistant
The error you're encountering is due to the incorrect use of template literals in your JSX code. In JSX, if you want to embed a JavaScript expression within a string, you need to use backticks (
) and the${}syntax properly. However, when you want to render dynamic content instead, you should wrap it in curly braces{}` without backticks for JSX. Here's how you can fix the issue:Incorrect
title: { text: ${symbol} Price Chart, },Correct
Wrap the
symboland the rest of the string in curly braces as a JavaScript expression without backticks:title: { text: `${symbol} Price Chart`, // Use backticks for string interpolation },Make sure to apply this change to correctly format your string with JavaScript expressions. This should resolve the syntax error you are experiencing in your
ChartOverlaycomponent. - User
i mean my code generated that error
- Assistant
The error message you're seeing indicates a syntax issue in your TypeScript/JavaScript code due to the incorrect use of template literals. Let's go through the code to ensure everything is properly formatted.