Here is the code snippet I tried to create a chart similar to bullet chart, I tried to pass a legend object into the ORFrame like this:
return <ORFrame
size={[ 500,100 ]}
data={data}
axis={axis}
projection={'horizontal'}
type={'bar'}
rExtent={[0,1000]}
style={d => {return {fill: d.colour}}}
oLabel={d => <text transform="translate(-75,28)">your {d}</text>}
oPadding={20}
oAccessor={d => d.name}
rAccessor={'value'}
margin={{ left: 85, top: 100, bottom: 50, right: 30 }}
hoverAnnotation={true}
annotations={exampleAnnotations}
legend={{ styleFn: d => ({ fill: d.color, stroke: "black" }), items: [
{ label: "Area 1", color: "red" },
{ label: "Area 2", color: "blue" }
]
}}
/>
Uncaught TypeError: Cannot read property 'forEach' of undefined
at Legend.render (eval at <anonymous> (bundle.js:3793), <anonymous>:86:19)
at eval (eval at <anonymous> (bundle.js:1795), <anonymous>:795:21)
at measureLifeCyclePerf (eval at <anonymous> (bundle.js:1795), <anonymous>:75:12)
at ReactCompositeComponentWrapper._renderValidatedComponentWithoutOwnerOrContext (eval at <anonymous> (bundle.js:1795), <anonymous>:794:25)
at ReactCompositeComponentWrapper._renderValidatedComponent (eval at <anonymous> (bundle.js:1795), <anonymous>:821:32)
at ReactCompositeComponentWrapper.performInitialMount (eval at <anonymous> (bundle.js:1795), <anonymous>:361:30)
at ReactCompositeComponentWrapper.mountComponent (eval at <anonymous> (bundle.js:1795), <anonymous>:257:21)
at Object.mountComponent (eval at <anonymous> (bundle.js:1429), <anonymous>:45:35)
at ReactDOMComponent.mountChildren (eval at <anonymous> (bundle.js:1765), <anonymous>:236:44)
at ReactDOMComponent._createInitialChildren (eval at <anonymous> (bundle.js:1633), <anonymous>:703:32)
import React, { Component } from 'react';
import { ORFrame, Legend } from 'semiotic';
export default class App extends Component {
render() {
const axis = {
orient: "bottom",
tickFormat: d => d,
tickValues: [0, 500, 1000],
padding: -10
};
const data = [
{
"colour":"lightblue",
"name":"score",
"value":800,
},
{
"colour":"lightgrey",
"name":"score",
"value":1000-800,
}
]
const exampleAnnotations = [
{"offset":40,"dy": -20,"dx":10,"value":430,"type":"r","label":"average score 430"},
{"offset":40,"dy": -20,"dx":10,"value":800,"type":"r","label":"your score 800"}
]
return <ORFrame
size={[ 500,100 ]}
data={data}
axis={axis}
projection={'horizontal'}
type={'bar'}
rExtent={[0,1000]}
style={d => {return {fill: d.colour}}}
oLabel={d => <text transform="translate(-75,28)">your {d}</text>}
oPadding={20}
oAccessor={d => d.name}
rAccessor={'value'}
margin={{ left: 85, top: 100, bottom: 50, right: 30 }}
hoverAnnotation={true}
annotations={exampleAnnotations}
legend={{ styleFn: d => ({ fill: d.color, stroke: "black" }), items: [
{ label: "Area 1", color: "red" },
{ label: "Area 2", color: "blue" }
]
}}
/>
}
}