Search code examples
reactjsd3.jsvictory-charts

How can I implement a legend like the attached in victory?


enter image description here

I am using victory to create charts, but VictoryLegend does not provide such kind of legend. Is there any existing react Legend component that can be used directly?


Solution

  • From a brief look at the docs it looks like victory does provide legends, read more here

    Here's a simple implementation from their docs:

    <VictoryLegend x={125} y={50}
      title="Legend"
      centerTitle
      orientation="vertical"
      gutter={20}
      style={{ border: { stroke: "black" }, title: {fontSize: 20 } }}
      data={[
        { name: "One", symbol: { fill: "tomato", type: "square" } },
        { name: "Two", symbol: { fill: "orange", type: "square" } },
        { name: "Three", symbol: { fill: "gold", type: "square" } }
      ]}
    />
    

    To create square shaped points specify type "square", other options are listed here.

    You can choose "circle", "diamond", "plus", "square", "star", "triangleDown", "triangleUp"