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

Colors won't show up for legends when I use DiscreteColorLegend for radial-chart

Open spunbell opened this issue 8 years ago • 2 comments

Hi, I've implemented a radial-chart using react-vis and now would like to display a legend showing the colors and titles. When I try to do this, the titles show up but not the colors for the legend. Can somehow please guide me as to where I am going wrong.

Here is my code -

 import * as React from 'react';
  import RadialChart from "react-vis/dist/radial-chart";
  import DiscreteColorLegend from 'react-vis/dist/legends/discrete-color-legend';

  const myData = [
      { angle: 171 / 3239, color: '#6742ca7a', name: '1*'},
      { angle: 54 / 3239, color: '#355cdcc9', name: '2*', opacity: 0.2 },
      { angle: 166 / 3239, color: '#42b4ca75', name: '3*'},
      { angle: 443 / 3239, color: '#4262ca78', name: '4*'},
      { angle: 2405 / 3239, color: '#4281ca85', name: '5*'}
  ];
  const ITEMS = [
      { title: '1 Star', color: '#6742ca7a', stroke: '#fff', strokeWidth: '2' },
      { title: '2 Star', color: '#355cdcc9', stroke: '#fff', strokeWidth: '2' },
      { title: '3 Star', color: '#42b4ca75', stroke: '#fff', strokeWidth: '2' },
      { title: '4 Star', color: '#4262ca78', stroke: '#fff', strokeWidth: '2' },
      { title: '5 Star', color: '#4281ca85', stroke: '#fff', strokeWidth: '2' }
  ];

  export default class RightPane extends React.Component {
      constructor(props) {
          super(props);
      }

    getStyles() {
        const that = this;
        return {
            base: {
                marginRight: '-35%',
                backgroundColor: 'rgb(240, 240, 240)',
                float: 'right',
                marginTop: '-830px',
                height: '841px',
                width: '300px'
            },
            innerDiv: {
                width: '240px',
                bottom: '520px',
                padding: '20px'
            },
            reviewSummary: {
                paddingLeft: '10px',
                paddingBottom: '20px',
                textAlign: 'justify'
            }
        }
    }

    PrintSummary(date, review, fiveStar, fourStar, threeStar, twoStar, oneStar) {
        return (
            <div style={this.getStyles().reviewSummary}>
                <h4> Review Summary </h4>
                <div> <h6> Date: {date} </h6> </div>
                <div> <h6>Total Reviews: {review} </h6></div>
                <div> <h6>5 star Reviews: {fiveStar} </h6></div>
                <div> <h6>4 star Reviews: {fourStar} </h6></div>
                <div> <h6>3 star Reviews: {threeStar} </h6></div>
                <div> <h6>2 star Reviews: {twoStar} </h6></div>
                <div> <h6>1 star Reviews: {oneStar} </h6></div>
            </div>
            );
    }

    render() {
        return (
            <div id="rightdiv" style={this.getStyles().base}>
                <div>
                    {this.PrintSummary('10-10-2018', '3239', '2405', '443', '166', '54', '171')}
                </div>
                <RadialChart
                    colorType={'literal'}
                    colorDomain={[0, 100]}
                    colorRange={[0, 10]}
                    margin={{ top: 100 }}
                    getLabel={d => d.name}
                    data={myData}
                    labelsRadiusMultiplier={1.1}
                    labelsStyle={{ fontSize: 16, fill: '#222' }}
                    showLabels
                    style={{ stroke: '#fff', strokeWidth: '2' }}
                    width={300}
                    height={250}
                />
            
           <DiscreteColorLegend
                    height={300}
                    width={300}
                    items={ITEMS}
                />
            </div>         
         );
    }
}

Here is an attached screenshot showing what I'm trying to explain - image

Any help is much appreciated. Please let me know if you want anything more from my side, this is my first time posting here, I could miss explaining something.

Regards, Spandana

spunbell avatar Oct 17 '18 18:10 spunbell

Hey @spunbell I tried loading you code locally, and it looks okay to me. I think your problem might be that you might not have imported the react-vis style sheet? To do so, check out the instructions on the readme/front page. If you have imported it, the edges might be clipped under your border on the left?

screen shot 2018-10-17 at 10 46 30 pm

Additionally, i don't know you build set up, but the way i've typically seen our package imported is by doing

import {RadialChart, DiscreteColorLegend} from 'react-vis';
`` 

(I don't think this has anything to do with your bug, just noting)

mcnuttandrew avatar Oct 18 '18 03:10 mcnuttandrew

Hi @mcnuttandrew !

Thanks for your suggestion, I checked my code and you were right, I didn't add the style sheet, but I was actually in a time-crunch and had to move to an other data viz library. But thank you so much for pointing me in the right direction.

spunbell avatar Oct 18 '18 20:10 spunbell