如何在VictoryCharts中将Axis gridComponent对准非零值

时间:2019-09-23 22:28:33

标签: reactjs victory-charts

我正在学习VictoryCharts。我想让我的X轴<VictoryAxis>平行于负y值,而不是沿着Y轴上的0。我遇到的问题是垂直网格线仍然在0上居中对齐,但是当我希望它们从我的轴开始时,它们向下延伸到X轴以下。有这样做的技巧吗?在文档中找不到任何内容。

这是一个代码示例:

<div >
      <VictoryChart
        width={800} height={300}
        theme={VictoryTheme.material}
      >
        <VictoryAxis
          axisComponent={<LineSegment type={"axis"} />}
          dependentAxis={true} //this means it is y axis?
          standalone={false}
          key="Y access"
          style={{
            tickLabels: { fontSize: 10, padding: 5 }
          }}
          domain={[-50, 50]}
        />

        <VictoryAxis name="X access"
          standalone={false}
          axisValue={-50} // NEED this axis to draw at bottom of Y axis
          domain={[1994, 2019]}
        />
      </VictoryChart>
    </div>

结果如下: Link to image of result

如果我通过如下所示的LineSegment属性向gridComponent添加手动偏移量,则它可以工作,但这似乎很麻烦,我必须弄清楚画布的高度和宽度才能使其正常工作。似乎我缺少了一些东西:

// adjusted VictoryAxis:
 <VictoryAxis name="X access"
          standalone={false}
          axisValue={-50} // NEED this axis to draw at bottom of Y axis
          domain={[1994, 2019]}
          gridComponent={<LineSegment y1={50} y2={250}/>} // do something here with LineSegment primitive properties to get it to start at proper y val...

Link to image of result

希望胜利图的退伍军人可以指引我正确的方向。

0 个答案:

没有答案