我的 React 页面上有一个条形图。它从另一个页面传递的 props 获取数据。我有一个显示三个不同数据的条形图。一个显示“正确”,另一个显示“不正确”,最后一个显示“总计”。我想让每个条形的颜色都不同。我尝试过使用单元格功能,但无法使其工作。我也尝试更改每条数据的名称,但没有成功。不幸的是,Recharts 的文档并不多。有人有什么想法吗?
import React from 'react';
import {
ResponsiveContainer, BarChart, Bar, Cell, XAxis, YAxis, CartesianGrid, Tooltip, Legend,
} from 'recharts';
export default class GameChart extends React.Component {
constructor(props) {
super(props);
this.state = {
axes: [
{ primary: true, type: 'ordinal', position: 'left' },
{ position: 'bottom', type: 'linear', stacked: true }
],
series: {
type: 'bar'
},
chartData: [
{
name: 'Correct',
total: 0,
},
{
name: 'Incorrect',
total: 0,
},
{
name: 'Total',
total: 0, …Run Code Online (Sandbox Code Playgroud) 当我使用 VS Code 的集成 bash 终端时,我没有任何正常的 bash 着色方案,我的所有文本都是白色的。如果我在 VS Code 之外使用 git bash,我会得到所有正常的目录颜色。
我尝试了这里接受的答案以及同一篇文章中提到的其他答案,但没有任何效果。我还确保将 bash 终端配置文件设置为正确的 exe 文件,但这也不起作用。我还阅读了 VS Code 关于终端配置文件的新文档,但我认为我的设置正确。我现在不知道还要检查什么,一切看起来都是正确的。有人有什么想法吗?
这是我的终端设置:
"terminal.integrated.defaultProfile.windows": "Command Prompt",
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
},
"Git Bash": {
"source": "Git Bash",
"icon": "terminal-bash",
"path": "C:\\Program Files\\Git\\bin\\bash.exe"
}
}
Run Code Online (Sandbox Code Playgroud)
这是一张显示 Git Bash、VS Code 的设置和我的 VS Code Bash 终端的图片。

VSC 内的 Bash:
$ echo $COLORTERM
truecolor
$ echo $PS1 …Run Code Online (Sandbox Code Playgroud) 以下是项目目标的快速背景:我正在尝试构建一个简单的数学游戏,当您单击按钮时,该游戏会提供随机的数学问题。稍后,我会想办法检查答案是否正确。我通过创建一个输入表单开始了这个过程。
我正在尝试使用 HTML 中的按钮在 javascript 数组中调用随机函数。该按钮调用一个随机函数,该函数在我刷新页面时决定。一旦我刷新页面,a 函数就会被随机选择,按钮继续一遍又一遍地给出该函数的结果。如果我刷新页面,该按钮只会调用不同的函数。
我希望每次单击按钮时都让按钮在我的数组中调用一个随机函数。有谁知道我怎么能做到这一点?
这是我的代码:
const btn = document.querySelector('#START')
const randomFunc = [
multiplication,
division,
addition,
subtraction,
]
btn.addEventListener(
'click', randomFunc[Math.floor(Math.random() * randomFunc.length)]
)
function multiplication(params) {
let num1 = Math.floor(Math.random() * 13);
let num2 = Math.floor(Math.random() * 13);
let problemResult = num1 * num2;
console.log(num1, '*', num2, '=', problemResult);
document.getElementById('mathProblem').innerHTML = (`${num1} * ${num2} =`);
}
function division(params) {
let num1 = Math.floor(Math.random() * 13);
let num2 = Math.floor(Math.random() * 12) + 1;
let problemResult …Run Code Online (Sandbox Code Playgroud)