首页 > 解决方案 > 如何在 react 中使用 chartkick.js 设置轴标签颜色?

问题描述

如果我在反应组件中有一个柱形图组件,如下所示:

import React from "react";
import {ColumnChart} from "react-chartkick";

export function BarChart({data, title, xlabel, ylabel}) {
  const classes = useStyles();
  return (
    <div className={classes.dataVisualisation}>
      <div className={classes.title} >{title}</div>
      <ColumnChart
        data={data}
        xtitle={xlabel}
        ytitle={ylabel}
      />
    </div>
  );
}

如何指定标签文本的颜色?

标签: javascriptreactjsjsxchartkick

解决方案


嗯,有点深。

我们可以在chartkick的文档中找到这些东西


库 > 图例 > 标签 > fontColor

图书馆 > 尺度 > yAxes/xAxes > gridLines (?) > 颜色

import Chartkick, { LineChart } from "react-chartkick";
import "chart.js";

<LineChart
  data={{ "2017-01-01": 11, "2017-01-02": 6, "2017-01-03": 20 }}
  library={{
    legend: {
      labels: {
        fontColor: "blue"
      }
    },
    scales: {
      xAxes: [
        {
          ticks: { fontColor: "blue" },
          gridLines: { drawBorder: true, color: "blue" }
        }
      ]
    }
  }}
/>

在此处输入图像描述


推荐阅读