Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[charts] Show reference colors in the gauge chart #13785

Open
josh-thompson13 opened this issue Jul 10, 2024 · 6 comments
Open

[charts] Show reference colors in the gauge chart #13785

josh-thompson13 opened this issue Jul 10, 2024 · 6 comments
Labels
component: charts This is the name of the generic UI component, not the React module! design This is about UI or UX design, please involve a designer enhancement This is not a bug, nor a new feature

Comments

@josh-thompson13
Copy link

josh-thompson13 commented Jul 10, 2024

The problem in depth

I need a way to color my gauge. See the attached image, the gauge on the right. Is it possible to do something like this? With multiple colors.

solid-angular-gauge-chart

Your environment

`npx @mui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Benchmarks

Search keywords: Gauge colors
Order ID:

@josh-thompson13 josh-thompson13 added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels Jul 10, 2024
@josh-thompson13
Copy link
Author

josh-thompson13 commented Jul 10, 2024

To add to this, I know I'm able to change the referenceArc color, so I'm wondering if I can conditionally set a fill color based on the position of the value arc? E.g. if arc is positioned between 75 - 100 fill with red.

 <Gauge
    value={value}
    startAngle={atrStartAngle}
    endAngle={atrEndAngle}
    text={() => (atrHideValue ? "" : `${atrPrefix ?? ""}${value}${atrSuffix ?? ""}`)}
    valueMax={atrMaxValue}
    valueMin={atrMinValue}
    sx={() => ({
        [`& .${gaugeClasses.valueText}`]: {
            fontSize: asNumber(atrFontSize).$or(() => undefined) ?? 12,
            transform: `translate(0px, ${atrRepositionValue ?? "0"}%)`,
        },
        [`.MuiGauge-referenceArc`]: {
            // Set conditional fill color based on arc location.
            fill: "red",
        },
    })}
    height={atrHeight}
/>

@alexfauquette
Copy link
Member

alexfauquette commented Jul 10, 2024

I'm not sure about what you want to create

I'm wondering if I can conditionally set a fill color based on the position of the value arc

Yes, the code you provided is good. You just need to replace the fill: "red", by something conditional to the value

https://codesandbox.io/p/sandbox/fragrant-microservice-zhnk9c?file=%2Fsrc%2FDemo.tsx%3A6%2C17

If you want to show the entire color mapping, it's not yet feasible. For the we would need to add the new colorMap threshold in the Gauge.

I was hopping to do it with some gradients, but unfortunately the conic gradients are not yet available with SVG

@alexfauquette alexfauquette added enhancement This is not a bug, nor a new feature component: charts This is the name of the generic UI component, not the React module! labels Jul 10, 2024
@alexfauquette alexfauquette changed the title How to use multiple different colors in the gauge chart. [charts] Show reference colors in the gauge chart Jul 10, 2024
@JCQuintas
Copy link
Member

@alexfauquette we can always try with a foreignObject 😅

@josh-thompson13
Copy link
Author

josh-thompson13 commented Jul 10, 2024

I'm not sure about what you want to create

I want to create a gauge similar to the one on the right hand side of the image I provided in my first comment. Essentially to show multiple colours in the reference arc. But I'm not sure it's quite possible yet.

@hoangqwe159
Copy link

It is my quick implementation if anyone needs it: https://codesandbox.io/p/sandbox/flamboyant-ganguly-hwnv6t?file=%2Fsrc%2Findex.tsx
CleanShot 2024-07-11 at 10 06 46

@michelengelen michelengelen removed the support: commercial Support request from paid users label Jul 15, 2024
@alexfauquette alexfauquette added docs Improvements or additions to the documentation and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jul 15, 2024
@jbrunner92
Copy link

jbrunner92 commented Sep 12, 2024

Would be nice if there were an easy way to implement segmented and gradient gauges. I don't love the idea of creating multiple gauge containers to make one parent gauge.

image
image

@oliviertassinari oliviertassinari added design This is about UI or UX design, please involve a designer and removed docs Improvements or additions to the documentation labels Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: charts This is the name of the generic UI component, not the React module! design This is about UI or UX design, please involve a designer enhancement This is not a bug, nor a new feature
Projects
None yet
Development

No branches or pull requests

7 participants