胜利图表,如何更改轴和标签颜色
Victory charts, how to change axis and label colors
这应该是一件很简单的事情,但是对于我来说我无法达到我想要的效果,我有一个图表,在深色背景上,这意味着我想改变标签的颜色变白,但是我做不到。
我使用的代码:
<VictoryChart
width={WIDTH}
// theme={VictoryTheme.material}
>
{/* <VictoryBar data={data} x="quarter" y="earnings" /> */}
<VictoryArea data={outcome} x="quarter" y="earnings" style={{ data: { fill: '#0074B7', fillOpacity: 0.7, stroke: '#0C7BBB', strokeWidth: 1 } }} />
{/* <VictoryArea data={income} x="quarter" y="earnings" style={{ data: { fill: '#9BC578', fillOpacity: 0.7, stroke: '#37B875', strokeWidth: 1 } }} /> */}
</VictoryChart>
感谢任何帮助。
我要更改图表编号,但我正在使用自定义主题来进行更改,但我想它是相似的。我在下面发布了一个例子
const chartTheme = {
axis: {
style: {
tickLabels: {
// this changed the color of my numbers to white
fill: 'white',
},
},
},
};
<VictoryChart theme={ chartTheme }>
<VictoryAxis label="Body Weight" />
<VictoryAxis dependentAxis label="Time" />
<VictoryLine
data={ [
{ x: 1, y: 2 },
{ x: 2, y: 3 },
{ x: 3, y: 5 },
{ x: 4, y: 4 },
{ x: 5, y: 7 },
] }
/>
</VictoryChart>
您可以添加 VictoryAxis,并分别修改各自的 x 轴和 y 轴以及标签:
<VictoryChart
width={WIDTH}
>
<VictoryAxis
tickLabelComponent={<VictoryLabel dy={0} dx={10} angle={55}/>}
tickValues={xAxisTickValues}
tickFormat={dateLabels}
style={{
axis: {
stroke: 'white' //CHANGE COLOR OF X-AXIS
},
tickLabels: {
fill: 'white' //CHANGE COLOR OF X-AXIS LABELS
},
grid: {
stroke: 'white', //CHANGE COLOR OF X-AXIS GRID LINES
strokeDasharray: '7',
}
}}
/>
<VictoryAxis
dependentAxis
tickFormat={(y) => y}
style={{
axis: {
stroke: 'white' //CHANGE COLOR OF Y-AXIS
},
tickLabels: {
fill: 'white' //CHANGE COLOR OF Y-AXIS LABELS
},
grid: {
stroke: 'white', //CHANGE COLOR OF Y-AXIS GRID LINES
strokeDasharray: '7',
}
}}
/>
<VictoryArea
data={outcome}
x="quarter"
y="earnings"
style={{
data: {
fill: '#0074B7',
fillOpacity: 0.7,
stroke: '#0C7BBB',
strokeWidth: 1
}
}}
/>
</VictoryChart>
这应该是一件很简单的事情,但是对于我来说我无法达到我想要的效果,我有一个图表,在深色背景上,这意味着我想改变标签的颜色变白,但是我做不到。
我使用的代码:
<VictoryChart
width={WIDTH}
// theme={VictoryTheme.material}
>
{/* <VictoryBar data={data} x="quarter" y="earnings" /> */}
<VictoryArea data={outcome} x="quarter" y="earnings" style={{ data: { fill: '#0074B7', fillOpacity: 0.7, stroke: '#0C7BBB', strokeWidth: 1 } }} />
{/* <VictoryArea data={income} x="quarter" y="earnings" style={{ data: { fill: '#9BC578', fillOpacity: 0.7, stroke: '#37B875', strokeWidth: 1 } }} /> */}
</VictoryChart>
感谢任何帮助。
我要更改图表编号,但我正在使用自定义主题来进行更改,但我想它是相似的。我在下面发布了一个例子
const chartTheme = {
axis: {
style: {
tickLabels: {
// this changed the color of my numbers to white
fill: 'white',
},
},
},
};
<VictoryChart theme={ chartTheme }>
<VictoryAxis label="Body Weight" />
<VictoryAxis dependentAxis label="Time" />
<VictoryLine
data={ [
{ x: 1, y: 2 },
{ x: 2, y: 3 },
{ x: 3, y: 5 },
{ x: 4, y: 4 },
{ x: 5, y: 7 },
] }
/>
</VictoryChart>
您可以添加 VictoryAxis,并分别修改各自的 x 轴和 y 轴以及标签:
<VictoryChart
width={WIDTH}
>
<VictoryAxis
tickLabelComponent={<VictoryLabel dy={0} dx={10} angle={55}/>}
tickValues={xAxisTickValues}
tickFormat={dateLabels}
style={{
axis: {
stroke: 'white' //CHANGE COLOR OF X-AXIS
},
tickLabels: {
fill: 'white' //CHANGE COLOR OF X-AXIS LABELS
},
grid: {
stroke: 'white', //CHANGE COLOR OF X-AXIS GRID LINES
strokeDasharray: '7',
}
}}
/>
<VictoryAxis
dependentAxis
tickFormat={(y) => y}
style={{
axis: {
stroke: 'white' //CHANGE COLOR OF Y-AXIS
},
tickLabels: {
fill: 'white' //CHANGE COLOR OF Y-AXIS LABELS
},
grid: {
stroke: 'white', //CHANGE COLOR OF Y-AXIS GRID LINES
strokeDasharray: '7',
}
}}
/>
<VictoryArea
data={outcome}
x="quarter"
y="earnings"
style={{
data: {
fill: '#0074B7',
fillOpacity: 0.7,
stroke: '#0C7BBB',
strokeWidth: 1
}
}}
/>
</VictoryChart>