简体   繁体   中英

Vega-tooltip in React application

I have a React application that uses vega-lite for data visualizations. I tried to use the official tooltip addon for vega ( https://github.com/vega/vega-tooltip ), however I have no idea how to do it in a React component.

This is the component I have:

import React from 'react';
import PropTypes from 'prop-types';
import VegaLite from 'react-vega-lite';

const VegaChart = ({data, spec}) => {
return(
<div className="vega-chart-wrapper">
<VegaLite spec={spec} data={data} />
</div>
)
}

VegaChart.propTypes = {
data: PropTypes.object.isRequired,
spec: PropTypes.object.isRequired
}

export default VegaChart;

From the documentation of vega-tooltip, it says that I can install the module and then I have to do this:

<!-- Placeholder for my scatter plot -->
<div id="vis-scatter"></div>

var opt = {
  mode: "vega-lite",
};
vega.embed("#vis-scatter", vlSpec, opt, function(error, result) {
  // result.view is the Vega View, vlSpec is the original Vega-Lite specification
  vegaTooltip.vegaLite(result.view, vlSpec);
});

This looks like the standard way to integrate in a jQuery application, but this is not gonna work in a React component. Any ideas?

Your react-vega-lite must already include vega-lite . So

import * as vega from 'vega-lite';

And put the rest in componentDidMount of your VegaChart

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM