如何将简单字体样式(更改大小)应用到React/Material-UI x-charts BarChart图例文本元素?文档表明:

Since the library relies on SVG for rendering, you can customize them as you do with other MUI components with CSS overriding. Chart components accept the sx props. From here, you can target any subcomponents with its class name.

然而,我一直无法使任何定制造型工作?

我曾try 创建StyledBarChart,然后将其与我的定制样式一起使用:

import { styled } from '@mui/material/styles';
import { BarChart } from "@mui/x-charts/BarChart";

const StyledBarChart = styled(BarChart)(({ theme }) => ({
    theme,
    "& .MuiChartsLegend-series text": {
        fontSize: '0.8em',
    },
}));

export default StyledBarChart;

并且还try 在BarChart组件上使用sx属性:

<BarChart
  sx={{ "& .MuiChartsLegend-series text": { fontSize: "0.8em" } }}
  dataset={...}
  series={[...]}
  xAxis={...}
/>

但是,在所有情况下,图例文本元素都会接收样式,该样式会覆盖我的所有CSS样式吗?我的最终HTML最终总是如下所示:

<text 
  x="11"
  y="0"
  text-anchor="start"
  dominant-baseline="central"
  style="font-family:
    Montserrat, sans-serif;
    font-weight: 400;
    font-size:1rem;
    line-height: 1;
    color: inherit;
    fill: rgba(0, 0, 0, 0.87);"
  >
  <tspan x="11" dy="0px" dominant-baseline="central">My Legend Text Item</tspan>
</text>

有没有办法为这些传说定制这个字体大小?

推荐答案

唯一对我有用的是在风格上增加!important:

<BarChart
  ...
  sx={{ "& .MuiChartsLegend-series text": { fontSize: "0.7em !important" }, }}
/>

Javascript相关问答推荐

将json数组项转换为js中的扁平

使用续集和下拉栏显示模型属性

类型自定义lazy Promise. all

React 17与React 18中的不同setState行为

将字符串UTC Date转换为ngx—counting leftTime配置值的数字

当运行d3示例代码时,没有显示任何内容

在观察框架中搜索CSV数据

Mongoose post hook在使用await保存时不返回Postman响应

数字时钟在JavaScript中不动态更新

为什么Mutations 观察器用微任务队列而不是macrotask队列处理?

获取Uint8ClampedArray中像素数组的宽度/高度

变量的值在Reaction组件中的Try-Catch语句之外丢失

在Java中寻找三次Bezier曲线上的点及其Angular

在SHINY R中的嵌套模块中,不能使用Java代码

是否可以将异步调用与useState(UnctionName)一起使用

为什么当雪碧的S在另一个函数中时,Phaser不能加载它?

如何在加载页面时使锚定标记成为焦点

如何从Reaction-Redux中来自API调用的数据中筛选值

react :图表负片区域不同 colored颜色

元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件),但GET:Object.在Reaction项目中