You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to use the original example of Scatter plot, and I have some code so that I render a specific color of the scatter indicator based on data values - if above X color is red, otherwise green.
However, I am having issues with getting the colors to work:
here is example DataPoint being sent to the chartData:
so I should be able to use style.color as I prepare the chartData for use by CartesianChart
interfaceChartDataPoint{
x: number;seated?: number;standing?: number;seatedColor?: string;standingColor?: string;
posture: POSTURE_PART;}constMetricChart=({ data, font }: {data: DataPoint[];font: any})=>{// Group data by timestamp and separate seated/standing valuesconstchartData=data.reduce<ChartDataPoint[]>((acc,point)=>{constexistingPoint=acc.find((p)=>p.x===point.x);if(existingPoint){if(point.posture===POSTURE_PART.SEATED){existingPoint.seated=point.y;existingPoint.seatedColor=point.style.color;// add data color to chart point }else{existingPoint.standing=point.y;existingPoint.standingColor=point.style.color;// add data color to chart point }}else{constnewPoint: ChartDataPoint={x: point.x,posture: point.posture,goalLine: point.goalLine,};if(point.posture===POSTURE_PART.SEATED){newPoint.seated=point.y;newPoint.seatedColor=point.style.color;// add data color to chart point }else{newPoint.standing=point.y;newPoint.standingColor=point.style.color;// add data color to chart point }acc.push(newPoint);}returnacc;},[]);return(<CartesianChartdata={chartData}xKey="x"yKeys={['seated','standing','goalLine']}// adding seatedColor & standingColor is resulting in TS error>{({ points, xScale, yScale })=>{return(<><Linepoints={points.seated}color={brand.disabled}strokeWidth={1.5}curveType="step"animate={{type: 'timing',duration: 300}}/><Linepoints={points.standing}color={brand.trademark}strokeWidth={1.5}curveType="step"animate={{type: 'timing',duration: 300}}/><Scatterpoints={points.seated}color={points.seatedColor}shape="circle"/> // color results in "black" which isn't one of the colors
<Scatterpoints={points.standing}color={points.standingColor}shape="square"/></>);}}</CartesianChart>);};
the acc from above looks like:
As you can see the data looks good - if standing there is standingColor, and if seated, there is seatedColor:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to use the original example of Scatter plot, and I have some code so that I render a specific color of the scatter indicator based on data values - if above X color is red, otherwise green.
However, I am having issues with getting the colors to work:
here is example
DataPoint
being sent to thechartData
:so I should be able to use
style.color
as I prepare thechartData
for use byCartesianChart
the
acc
from above looks like:As you can see the data looks good - if standing there is
standingColor
, and if seated, there isseatedColor
:how come I can render
points.seated
,but notpoints.seatedColor
?I figured I could try to map the current point index to the original chartData and get the color, but there's no index or callback from
color
prop.Any ideas?
Beta Was this translation helpful? Give feedback.
All reactions