胜利图表,如何更改轴和标签颜色

时间:2019-03-09 18:28:29

标签: javascript victory-charts

这应该是一件非常简单的事情,但是对于我一生来说,我无法达到我想要的效果,我在深色背景上有一张图表,这意味着我想将标签的颜色更改为白色,但是我无法实现。

enter image description here

我正在使用的代码:

<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>

感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

您可以添加 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>

答案 1 :(得分:0)

我更改了图表编号,但是我正在使用自定义主题进行更改,但我可以想象它的相似之处。我在下面发布了一个示例

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>
相关问题