Comments (7)
About why you need to pass the mouse over, the props.style.y.animation.to
is NaN
at first render so your component does not render.
About how to get the information, using the useScale
sounds to be ok. Maybe better would be that we pass this information to the component to simplify this.
For now, the ownerState
get id
and dataIndex
which are the series' id and the index of the data rendered. So if you data is not too complicated, the best might be to rely on that information.
from mui-x.
I solved this using the useYScale
hook. Not sure if it's the best solution. Feedback appreciated.
A side affect is that the hover element has the wrong bar color associated
Once the BarElement export fix is released the custom rect can be replaced. #11234
Updated Code Pen: https://codesandbox.io/p/sandbox/mui-bar-chart-with-rounded-corders-right-forked-trvfp4?file=%2FDemo.js
export const BarChart = () => {
const SlotBarElement = (props) =>{
const yAxisScale = useYScale('left_axis_id')
const yAxisValue = yAxisScale.invert(props.style.y.animation.to)
const isBelowBar = yAxisValue < 8.5
const color = isBelowBar ? '#ff0000' : '#00ff00'
// work around export of BarElement
return <rect
fill={color}
height={props.style.height.animation.to}
width={props.style.width.animation.to}
x={props.style.x.animation.to}
y={props.style.y.animation.to}
/>
}
return (
<ResponsiveChartContainer
height={350}
series={[
{ type: 'bar', data: [11, 10, 1, 9], yAxisKey: 'left_axis_id'},
]}
xAxis={[{ scaleType: 'band', data: ['11/15', '11/16', '11/17', '11/18'] }]}
yAxis={[{ id: 'left_axis_id'}]}
>
<BarPlot slots={{bar: SlotBarElement}}/>
<ChartsXAxis />
<ChartsYAxis axisId="left_axis_id" position="left"/>
<ChartsReferenceLine label={'8.5'} labelAlign="end" y={8.5}/>
<ChartsTooltip/>
</ResponsiveChartContainer>
)
}
from mui-x.
For some reason the colors do not change automatically. Sometimes I have to mouse over the chart before they swap. Any thoughts why?
from mui-x.
Thank you @alexfauquette this resolved my problem!!
from mui-x.
I'm just keeping this issue open to track the progress on simplifying conditional rendering of bar elements
from mui-x.
I'm just keeping this issue open to track the progress on simplifying conditional rendering of bar elements
Makes sense..
I noticed the tooltip popup shows the default bar color and not the custom color of the bar. It's not a big deal for me, but figured I'd call it out since you're using this for tracking.
from mui-x.
I noticed the tooltip popup shows the default bar color and not the custom color of the bar.
Interesting. That's a sign the customization should probably not be into the component customization (bar, line, ...) but at a higher level to have coherence between chart element, the legend and the tooltip
from mui-x.
Related Issues (20)
- [charts] The tooltip should get a position option
- I have the following order, when will I be able to download my license key? HOT 1
- [data grid] valueFormatter doesn't show the updated value after processRowUpdate HOT 19
- [DateTimePicker] PickerField shows `0NaN` for year portion of formatted input field value when using Eastern Arabic numerals HOT 5
- [data grid] include rows / leaf nodes prop in custom aggregation callback HOT 1
- MUI DataGrid Pro - restoreState with Column dimensions and columnVisibilityModel ignores column dimensions HOT 1
- [pickers] Required field does not work as expected for DatePicker HOT 1
- NextJs Mui x-Charts Bar colors go black HOT 2
- Can't close (delete) Data Grid column filter if type = 'singleSelect', operator = 'is any of' HOT 2
- Module not found: Package path ./_lib/format/longFormatters is not exported from package date-fns in version v6.18.6 HOT 1
- [tree view] onBlur event causes TreeView performance issues
- Time picker default value in Mac OS HOT 1
- [pickers] When embedded inside iframe focus shifts to top of iframe when clicked HOT 7
- [docs] Add Pickers RTL support section
- [data grid] Input type number lets type non number. HOT 8
- [pickers] `MultiSectionDigitalClock` incorrect RTL behavior HOT 6
- [data grid] Filtering on non filterable columns yield weird behavior
- [tree view] Polish the look and feel HOT 1
- [data grid] Autosizing does not adjust when an individual column's width is set by the user HOT 3
- MuiPickersFadeTransitionGroupRoot: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead. HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mui-x.