React UI Components Documentation

ReactJS TagCloud Component

The TagCloud component for ReactJS represents a flexible UI component that displays a collection of user-generated tags accompanying the articles, posts, or videos on your website.

Prerequisites

Refer to ReactJS Getting Started before you start with this help topic.

Configuration

The TagCloud component for ReactJS requires the following imports.

 
import React from 'react';
import ReactDOM from 'react-dom';
import JqxTagCloud from 'jqwidgets-react/react_jqxtagcloud.js';

Then we create our component class. Properties and methods are put as ReactJS props.

 
class App extends React.Component {
render () {
let data = [
{ countryName: "Australia", technologyRating: 35 },
{ countryName: "United States", technologyRating: 60 },
{ countryName: "Germany", technologyRating: 55 },
{ countryName: "Brasil", technologyRating: 20 },
{ countryName: "United Kingdom", technologyRating: 50 },
{ countryName: "Japan", technologyRating: 80 }
];
let source =
{
localdata: data,
datatype: "array",
datafields: [
{ name: 'countryName' },
{ name: 'technologyRating' }
]
};
let dataAdapter = new $.jqx.dataAdapter(source);
return (
<JqxTagCloud
width={600} source={dataAdapter}
displayMember={'countryName'} valueMember={'technologyRating'}
/>
)
}
}

Finally we render our class in the desired HTML element:

 
ReactDOM.render(<App />, document.getElementById('app'));

Events Methods & Properties

In order to bind to any event, change any property or call any method, we need a reference to the component.
For that we use the ReactJS "ref" Callback Attribute:

 
<JqxTagCloud ref='myTagCloud' width={600} source={dataAdapter}...../>

Now, when we have a reference, we need to call the desired event/property/method.
This is done in the componentDidMount() ReactJS Component Lifecycle method.

 
class App extends React.Component {
componentDidMount()
{
//your logic
}
render ()
{
return
(
....
)
}
};

Events

The bindingComplete event is triggered when the widget has completed binding to a dataAdapter.

The following example demonstrates how to add an event listener:

 
componentDidMount ()
{
this.refs.myTagCloud.on('bindingComplete', (event) =>
{
//your logic
});
}

Methods & Properties

This is how you call methods & props:

 
//Get Methods
let hidden = this.refs.myTagCloud.getHiddenTagsList();
//Set Methods
this.refs.myTagCloud.updateAt(index, tagItem);
//Get Properties
let height = this.refs.myTagCloud.height();
//Set Properties
this.refs.myTagCloud.height(50);

Every component have a method setOptions which accepts a object as an argument. This object contains component settings.

 
this.refs.myTagCloud.setOptions({
maxFontSize: 30, width: 500, height: 150
})

Every component also have a method getOptions which returns a object containing the component settings.

 
let options = this.refs.myTagCloud.getOptions();

TagCloud Examples

Overview

The following example demonstrates how to create a TagCloud component.

 
import React from 'react';
import ReactDOM from 'react-dom';
import JqxTagCloud from 'jqwidgets-react/react_jqxtagcloud.js';
class App extends React.Component {
render () {
let data = [
{ countryName: "Australia", technologyRating: 35 },
{ countryName: "United States", technologyRating: 60 },
{ countryName: "Germany", technologyRating: 55 },
{ countryName: "Brasil", technologyRating: 20 },
{ countryName: "United Kingdom", technologyRating: 50 },
{ countryName: "Japan", technologyRating: 80 }
];
let source =
{
localdata: data,
datatype: "array",
datafields: [
{ name: 'countryName' },
{ name: 'technologyRating' }
]
};
let dataAdapter = new $.jqx.dataAdapter(source);
return (
<JqxTagCloud
width={600} source={dataAdapter}
displayMember={'countryName'} valueMember={'technologyRating'}
/>
)
}
}
ReactDOM.render(<App />, document.getElementById('app'));

Disabled TagCloud

The following example demonstrates how to disable the TagCloud component.

TagCloud API

API Reference of the jQWidgets TagCloud component for React: TagCloud API