reactjschartsreact-vis

Bar series not rendering correctly under label using the react-vis library


I'm running into a problem. The bar series is not coming right under it's label. I can't figure out what is going wrong.

enter image description here

Here is the code for it

const FlexibleXYPlot = makeWidthFlexible(XYPlot);


<FlexibleXYPlot height={graphContainer.height} margin={graphContainer.margin} xDistance={0} xType="ordinal">
        <HorizontalGridLines />
        <XAxis/>
        <YAxis orientation="right" style={yAxisStyles} />
        {  this.state.data.map((lineData, i) => (
      <VerticalBarSeries
        key={i}
        data={lineData.timeline}
      />
    )); }
      </FlexibleXYPlot>

and the data is this

[
    {
      "timeline": [
        {
          "x": "dataA",
          "y": 12.21
        }
      ]
    },
    {
      "timeline": [
        {
          "x": "dataB",
          "y": 21.09
        }
      ]
    },
    {
      "timeline": [
        {
          "x": "dataC",
          "y": 16.66
        }
      ]
    }

Solution

  • I figured it out.

    For each bar I was creating a separate series. I just had to pass the whole data to a single series. Now if somebody wants each bar to have a different color in a single series they can pass the color with the data like given below

    [
        {
              "x": "dataA",
              "y": 12.21,
              "color": <something>
        },
        {
    
              "x": "dataB",
              "y": 21.09,
              "color": <something>
        },
        {
              "x": "dataC",
              "y": 16.66,
              "color": <something>
        }
    ]
    

    and we need to pass colorType="literal" to the series itself.