我有来自MUI的以下SparkLine图表

import * as React from 'react';
import Stack from '@mui/material/Stack';
import Box from '@mui/material/Box';
import { SparkLineChart } from '@mui/x-charts/SparkLineChart';

export default function CustomAxis() {
  return (
    <Stack direction="row" sx={{ width: '100%' }}>
      <Box sx={{ flexGrow: 1 }}>
        <SparkLineChart
          data={[1, 4, 2, 5, 7, 2, 4, 6]}
          xAxis={{
            scaleType: 'time',
            data: [
              new Date(2022, 5, 1),
              new Date(2022, 5, 2),
              new Date(2022, 5, 5),
              new Date(2022, 5, 6),
              new Date(2022, 5, 7),
              new Date(2022, 5, 8),
              new Date(2022, 5, 11),
              new Date(2022, 5, 12),
            ],
            valueFormatter: (value) => value.toISOString().slice(0, 10),
          }}
          height={100}
          showTooltip
          showHighlight
        />
      </Box>
    </Stack>
  );
}

And for this, chart gets generated as enter image description here

我想在工具提示中添加一个‘$’符号作为‘$7’,而不仅仅是‘7’. 我try 将整型数组中的数据转换为字符串整型数组,但图表呈现程序抛出一个错误,指出数据应该是整型的.

如有任何帮助,不胜感激

谢谢,

推荐答案

还有一个类似的example here:

...
const yearFormater = (date: Date) => date.getFullYear().toString();
const currencyFormatter = new Intl.NumberFormat('en-US', {
  style: 'currency',
  currency: 'USD',
}).format;

export default function Formatting() {
  return (
    <LineChart
      {...lineChartsParams}
      xAxis={[{ data: years, scaleType: 'time', valueFormatter: yearFormater }]}
      series={lineChartsParams.series.map((s) => ({
        ...s,
        valueFormatter: currencyFormatter,
      }))}
    />
  );
}

在您的情况下,它将是:

    <SparkLineChart
      data={[1, 4, 2, 5, 7, 2, 4, 6]}
      valueFormatter={currencyFormatter}
      xAxis={{ ...

Javascript相关问答推荐

当promise 在拒绝处理程序被锁定之前被拒绝时,为什么我们会得到未捕获的错误?

深嵌套的ng-container元素仍然可以在Angular 布局组件中正确渲染内容吗?

在服务器上放置了Create Reaction App Build之后的空白页面

WebGL 2.0无符号整数输入变量

如何将react—flanet map添加到remixjs应用程序

如何在Angular拖放组件中同步数组?

为什么这个.add.group({})在教程中运行得很好,但在我的游戏中就不行了?

使用带有HostBinding的Angular 信号来更新样式?

创建以键值对为有效负载的Redux Reducer时,基于键的类型检测

Reaction-SWR-无更新组件

有没有一种直接的方法可以深度嵌套在一个JavaScript对象中?

在D3条形图中对具有相同X值的多条记录进行分组

P5JS-绘制不重叠的圆

JavaScript -复制到剪贴板在Windows计算机上无效

我怎样才能得到一个数组的名字在另一个数组?

使用Library chart.js在一个带有两个y轴的图表中绘制两个数据集

在范围数组中查找公共(包含)范围

Refine.dev从不同的表取多条记录

JSON Web令牌(JWT)错误:RSA密钥对的签名无效

使用jQuery每隔几秒钟突出显示列表中的不同单词