Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting Series name #5

Open
mbugbee opened this issue Mar 6, 2018 · 3 comments
Open

Setting Series name #5

mbugbee opened this issue Mar 6, 2018 · 3 comments

Comments

@mbugbee
Copy link

mbugbee commented Mar 6, 2018

What's the proper way to set the name of a series with anychart-react?

@Shestac92
Copy link

@mbugbee You can achieve it with customizing anychart-react.jsx file. Find createAndDraw(prevProps) {} function and customize it like this:

createAndDraw(prevProps) {
    var props = Object.assign(prevProps, this.props);
    this.createInstance(props);
    this.drawInstance(props);
    this.instance.getSeries(0).name('Series name');   //set name to the first series
  }

@mbugbee
Copy link
Author

mbugbee commented Mar 7, 2018

ah, editing files in an npm module doesn't seem like a great long term solution as the edit would be reverted anytime the dependency was updated or pulled in other environments. This would also force every chart using anychart-react to have the same series 0 name.

@Shestac92
Copy link

Shestac92 commented Mar 8, 2018

@mbugbee I have a better solution for how you can set a series name and customize deeply your chart. If you do not use an instance property of a component, properties go exactly as they go in AnyChart JavaScript API. An example of such chart configuration below:

// create data
    var data = [
      ["January", 10000],
      ["February", 12000],
      ["March", 18000],
      ["April", 11000],
      ["May", 9000]
    ];

    // create a chart
    var chart = anychart.line();
    // create a line series and set the data
    var series = chart.line(data);
    //set series name
    series.name('Series name');

ReactDOM.render(
  <AnyChart
    width='100%'
    height='100%' 
        instance={chart}
    title="Simple pie chart"
  />, document.getElementById('root'));

This allow setting names to series:
seriesname

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants