5

我尝试使用 react-chartjs ( https://github.com/reactjs/react-chartjs ) 制作雷达图。它渲染,但没有颜色。

在此处输入图像描述

我错过了什么?我几乎复制了https://reactcommunity.org/react-chartjs/index.html上的大部分示例。(我将数据简化为一个数据集。)

import React, {PropTypes} from 'react';
import {Grid} from 'react-bootstrap';
const {Radar} = require("react-chartjs");
const ReactDOM = require('react-dom');

function rand(min, max, num) {
	var rtn = [];
	while (rtn.length < num) {
		rtn.push((Math.random() * (max - min)) + min);
	}
	return rtn;
}

var chartData = {
	labels: ["Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running"],
	datasets: [
	{
		label: "My First dataset",
		backgroundColor: "rgba(179,181,198,0.2)",
		borderColor: "red",
		pointBackgroundColor: "rgba(179,181,198,1)",
		pointBorderColor: "#fff",
		pointHoverBackgroundColor: "#fff",
		pointHoverBorderColor: "rgba(179,181,198,1)",
		data: [65, 59, 90, 81, 56, 55, 40]
	}
	]
};

var chartOptions = {
	scale: {
		reverse: true,
		ticks: {
			beginAtZero: true
		}
	}
};

function TasteGraph({rating}) {
	//loop through and output one slider and one value per component
	return (
		<div>
		<Radar data={chartData} options={chartOptions}/>
		</div>
		);

}
TasteGraph.propTypes = {
	rating: PropTypes.array
};

TasteGraph.defaultProps = {
	rating: []
};

export default TasteGraph;

似乎没有任何导入丢失或清除错误。根据另一个相关的 SO 问题,我尝试用“[”和“]”围绕 chartOptions 和 ChartData。

4

1 回答 1

3

替换backgroundColorfillColor。可能你的borderColor也应该替换为strokeColor.

请参阅此jsfiddle。(它使用不带反应包装器的 chart.js - 但您的属性给出的输出与屏幕截图中的相同)

于 2017-02-14T07:15:54.167 回答