<div id="root" style="padding: 24px"></div>
'use strict';

const QueryRenderer = cubejsReact.QueryRenderer;
const {LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend} = Recharts;

class ReactExample extends React.Component {
  constructor(props) {
    super(props);
    this.state = {};
    this.api = cubejs('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpIjozODU5NH0.5wEbQo-VG2DEjR2nBpRpoJeIcE_oJqnrm78yUo9lasw');
    this.chartRef = React.createRef();
  }

  render() {
    return (<div>
      <QueryRenderer query={{
        measures: ["Stories.count"],
        dimensions: ['Stories.time.month'],
        filters: [{
          dimension: "Stories.time",
          operator: 'inDateRange',
          values: ["2015-01-01", "2016-01-01"]
        }]
      }} cubejsApi={this.api} render={
        ({ resultSet, error }) => {
          if (error) {
            return <div>{error.stack}</div>;
          } else if (resultSet) {
            return (
              <LineChart width={600} height={300} data={resultSet.rawData()}
                               margin={{top: 5, right: 30, left: 20, bottom: 5}}>
                <XAxis dataKey="Stories.time"
                       tickFormatter={(v) => moment(v).format('MMM YY')}
                />
                <YAxis/>
                <CartesianGrid strokeDasharray="3 3"/>
                <Tooltip/>
                <Legend />
                <Line type="monotone" dataKey="Stories.count" stroke="#8884d8"/>
              </LineChart>
            )
          }
          return null;
        }
      }
      />
    </div>);
  }
}

ReactDOM.render(<ReactExample/>, document.getElementById("root"));
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://unpkg.com/prop-types@15.6/prop-types.min.js
  2. https://unpkg.com/react@16/umd/react.development.js
  3. https://unpkg.com/react-dom@16/umd/react-dom.development.js
  4. https://npmcdn.com/recharts@1.2.0/umd/Recharts.min.js
  5. https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.js
  6. https://unpkg.com/@cubejs-client/core@0.1.0/dist/cubejs-client-core.umd.js
  7. https://unpkg.com/@cubejs-client/react@0.1.0/dist/cubejs-react.umd.js