react-charts icon indicating copy to clipboard operation
react-charts copied to clipboard

No application of chart color per series

Open silas-v1 opened this issue 4 years ago • 4 comments

Version: 3.0.0-beta32

It's expected that a serie containing a color would be utilized:

{
    label: "Average Ranking",
    data: [
      { primary: new Date("2021-10-01"), secondary: 20 },
      { primary: new Date("2021-10-02"), secondary: 21 },
      { primary: new Date("2021-10-03"), secondary: 22 },
      { primary: new Date("2021-10-04"), secondary: 22 },
      { primary: new Date("2021-10-05"), secondary: 25 },
      { primary: new Date("2021-10-06"), secondary: 25 },
      { primary: new Date("2021-10-07"), secondary: 28 },
      { primary: new Date("2021-10-08"), secondary: 29 },
      { primary: new Date("2021-10-09"), secondary: 29 },
      { primary: new Date("2021-10-10"), secondary: 30 }
    ],
    secondaryAxisId: "2",
    color: "#81bea6"
  }

But the UI doesn't show the color.

Please refer: https://codesandbox.io/s/chart-color-issue-l0fqv

silas-v1 avatar Oct 05 '21 21:10 silas-v1

Luckily, I have found a workaround. You can use the defaultColors options prop of the Chart and add a color for each serie (correct me if terms are wrong).

Let's keep this open as the the original issue does persist.

silas-v1 avatar Oct 07 '21 00:10 silas-v1

Running into the same issue, I am on [email protected]. Seems there is another slight bug with your suggested workaround in that each series is offset from the center tick on the x axis making the alignment look not too great.

jrymer avatar Apr 17 '22 03:04 jrymer

@j-sup It looks like using defaultColors does change the graph, but not the ticks. Any idea how to change the color of the data ticks?

Image for reference, has the ticks selected to show. They do not show normally. Screen Shot 2022-05-12 at 5 44 19 PM

Screen Shot 2022-05-12 at 5 43 16 PM

christopher-caldwell avatar May 12 '22 22:05 christopher-caldwell

Was able to fix my issues specifically with CSS / styled components for anyone interested.

Screen Shot 2022-05-12 at 6 38 36 PM

const ChartContainer = styled(ResizableBox)`
  & .tickLabel {
    fill: blue;
  }
  & .tick {
    & line {
      stroke: blue;
      stroke-width: 0.2px;
    }
  }
`

<ChartContainer>
   <Chart
    options={{
      data,
      interactionMode: 'closest',
      defaultColors: ['blue'],
      primaryAxis,
      secondaryAxes
    }}
  />
</ChartContainer>

christopher-caldwell avatar May 12 '22 23:05 christopher-caldwell