gpt-4-0314· openai
Suzhen/CodeChat
https://recharts.org/en-US/examples/SimpleLineChart <ResponsiveContainer height={260}…
- User
https://recharts.org/en-US/examples/SimpleLineChart
<ResponsiveContainer height={260} width="100%" > <LineChart data={profitData}> <XAxis dataKey="date" /> <YAxis /> <Tooltip formatter={function (val) { return parseFloat(${val}).toFixed(1); }} /> <Line type="monotone" dataKey="profit" stroke="#006943" strokeWidth={2} dot={false} /> </LineChart> </ResponsiveContainer>можно ли сделать Line с заостренными углами?
- Assistant
К сожалению, библиотека Recharts не предоставляет встроенной опции для создания линии с заостренными углами напрямую. Однако вы можете определить свою собственную реализацию формы линии, передав свою кастомную компоненту в свойство
shapeкомпонента<Line>.Пример кастомной формы линии с заостренными углами:
import React from 'react'; import { LineChart, Line, XAxis, YAxis, Tooltip, ResponsiveContainer } from 'recharts'; const SharpLine = ({ points }) => { const path = points.reduce((str, point, idx) => { const [x, y] = [point.x, point.y]; return idx === 0 ? `M ${x},${y}` : `${str} L ${x},${y}`; }, ''); return <path d={path} fill="none" stroke="#006943" strokeWidth={2} />; }; const SimpleLineChart = ({ profitData }) => ( <ResponsiveContainer height={260} width="100%"> <LineChart data={profitData}> <XAxis dataKey="date" /> <YAxis /> <Tooltip formatter={(val) => { return parseFloat(val).toFixed(1); }} /> <Line type="monotone" dataKey="profit" dot={false} shape={<SharpLine />} /> </LineChart> </ResponsiveContainer> ); export default SimpleLineChart;
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.