Rendering Arbitrary Shape in Charts
See original GitHub issueDo you want to request a feature or report a bug?
Feature
What is the current behavior?
API docs mention arbitrary shapes such as Polygon, which leads me to believe that I should be able to include these shapes as part of a chart. For example, something like this:
const data = [
{x: 100, y: 200}, {x: 120, y: 100}, {x: 170, y: 300},
{x: 140, y: 250}, {x: 150, y: 400}, {x: 110, y: 280},
];
const polygon = [
{x: 45, y:100}, {x: 45, y:200}, {x: 90, y:200}, {x: 90, y:100},
];
return (
<ScatterChart width={400} height={400} margin={{top: 20, right: 20, bottom: 20, left: 20}}>
<XAxis type={'number'} dataKey={'x'} name='stature' unit='cm'/>
<YAxis dataKey={'y'} name='weight' unit='kg'/>
<CartesianGrid />
<Scatter name='A school' data={data} fill='#8884d8'/>
<Tooltip cursor={{strokeDasharray: '3 3'}}/>
<Polygon data={polygon} fill='#8884d8'/>
</ScatterChart>
);
However, it seems that there is only a list of children expected of any particular chart, and anything else is ignored. So, Polygon
inside any chart is not rendered at all.
What is the expected behavior?
Shapes inside chart can be added and rendered as a layer within the same coordinate system. The above code should render something like this:
Which versions of Recharts, and which browser / OS are affected by this issue? Did this work in previous versions of Recharts?
1.0.0-alpha.6
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (2 by maintainers)
Top Results From Across the Web
(PDF) Improving Shape Depiction under Arbitrary Rendering
Based on the observation that shading conveys shape information through intensity gradients, we present a new technique called Radiance ...
Read more >Chart.js — drawing an arbitrary vertical line - Stack Overflow
You extend the line chart and include logic for drawing the line in the draw ... const context = chartInstance.chart.ctx; // render vertical...
Read more >Unable to draw 2D closed shapes - Nevron Software
But I need to draw irregular shapes - with arbitrary outlines. ... Gallery \ Custom \ Custom Series - using this approach you...
Read more >XYAreaRenderer - JFree
Area item renderer for an XYPlot . This class can draw (a) shapes at each point, or (b) lines between points, or (c)...
Read more >Multi-chart geometry images - JHU CS
... we use an atlas construction to map the surface piecewise onto charts of arbitrary shape. ... rendering involves a simple scan of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@xile611 I’m aware of that, but I will have to put in actual svg coordinates, rather than data points on the same scale as my normal data series. I’ve got a decent implementation using
ReferenceArea
working already, I can open a PR if you are interested. 😃For those who are looking for a way to draw own components and shapes inside of the chart. As mentioned above charts check the type of children and render only allowed types which include valid svg elements. If you pass
<polygon>
it should be rendered, but<Polygon>
should not because it is a Rechart’s component used internally(?). So every direct child of chart should be either one of allowed types (see docs for it) or svg element.If you try to put your own component that renders svg you would wonder that it is not rendered. That’s because the type of component is that you write in JSX. I found two options to get around this.
Brush
under the chart).<foreignObject>
that is valid svg element allows to place non-svg stuff inside.