Instead of using url
s, use a click ("hit"
) event to stay within the React ecosystem. If you allow the chart component to be rendered via React Router and export it with withRouter
, you can take advantage of this.props.history
on the component itself. As for how to handle the member's name, presuming the bullet
is actually the template for other bullets, I personally believe the member's name should be part of the chart's data. E.g.
Main component:
import React, { Component } from "react";
import ReactDOM from "react-dom";
import { Route, BrowserRouter as Router } from "react-router-dom";
// ...
// main component's render
<Router>
<React.Fragment>
<Route
path="/"
render={props => <App {...props} />}
/>
<Route
path="/Member/:name"
render={props => <Person {...props} extra="via router" />}
/>
</React.Fragment>
</Router>
Component that has your chart (e.g. App):
import React from "react";
import { withRouter } from "react-router-dom";
import * as am4core from "@amcharts/amcharts4/core";
import * as am4charts from "@amcharts/amcharts4/charts";
import am4themes_animated from "@amcharts/amcharts4/themes/animated";
// App's componentDidMount() ...
// ...chart code...
// Member names found in bullet data
chart.data = [ { name: "...", /* ... */ }, /* ... */ ];
// Since we're not using `url`, manually change the cursor to a pointer on hover
bullet.cursorOverStyle = am4core.MouseCursorStyle.pointer;
// Bullet click event
bullet.events.on("hit", event => {
this.props.history.push('../Members/' + event.target.dataItem.dataContext.name);
});
// ... end App
export default withRouter(App);
Here's a fork of our Column charts with images at top demo in React that when clicking the bullet/images, both updates the main component's state as well as goes to a new URL, and both load the person's info:
https://codesandbox.io/s/olpzok2rxz
If the member.name
is not part of the chart data and cannot be, it would help to have a sample of your app whether on JSFiddle or CodeSandbox so we can help further.