Giter Site home page Giter Site logo

keen / keen-react-charts Goto Github PK

View Code? Open in Web Editor NEW
6.0 4.0 2.0 4.94 MB

A React Component for Keen-Dataviz.js

Home Page: https://keen.io

License: MIT License

JavaScript 91.86% CSS 1.14% HTML 7.00%
keen-dataviz react react-visualizations react-charts

keen-react-charts's Introduction

Keen charts react component

Install with NPM

npm install keen-react-charts --save

Usage

Use this component to create charts from the data received from the Keen's API. Charts expect a results prop of the response from the query or a raw object. All the configuration properties could be passed in props.

Example

import React from 'react';
import ReactDOM from 'react-dom';
import Chart from 'keen-react-charts';
import KeenAnalysis from 'keen-analysis';

import 'keen-dataviz/dist/keen-dataviz.css';
import './styles/style.css';

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      type: 'funnel',
      title: 'Actions and purchases',
      labelMapping: {
        pageviews: 'Pageviews',
        banner_visibility: 'Banner visibility',
        banner_clicks: 'Banner clicks',
        signups: 'Signups',
      },
      funnel: {
        lines: false,
        percents: {
          show: true,
        },
        resultValues: false
      },
      renderOnVisible: true
    };
  }

  componentDidMount() {
    const client = new KeenAnalysis({
      projectId: 'YOUR_PROJECT_ID',
      readKey: 'YOUR_READ_KEY'
    })
      .query({
        analysis_type: 'funnel',
        steps: [
          {
            event_collection: 'pageviews',
            actor_property: 'user.uuid',
            timeframe: {
              start: '2019-03-13T00:00:00.000Z',
              end: '2019-08-14T00:00:00.000Z'
            }
          },
          {
            event_collection: 'banner_visibility',
            actor_property: 'user.uuid',
            timeframe: {
              start: '2019-03-13T00:00:00.000Z',
              end: '2019-08-14T00:00:00.000Z'
            }
          },
          {
            event_collection: 'banner_clicks',
            actor_property: 'user.uuid',
            timeframe: {
              start: '2019-03-13T00:00:00.000Z',
              end: '2019-08-14T00:00:00.000Z'
            }
          },
          {
            event_collection: 'signups',
            actor_property: 'user.uuid',
            timeframe: {
              start: '2019-03-13T00:00:00.000Z',
              end: '2019-08-14T00:00:00.000Z'
            }
          }
        ],
      })
      .then((results) => {
        this.setState({
          results,
        });
      });
  }


  render() {
    return (
      <Chart {...this.state} />
    );
  }
}

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

Configuration

Charts configurations you can check here: keen-dataviz.js

keen-react-charts's People

Contributors

adamkasprowicz avatar dariuszlacheta avatar stassiek02 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

viraj99 forkkit

keen-react-charts's Issues

Can't Dynamically Set Size For Chart

My goal is to let different charts have different sizes. For example, I might have a size prop in my component, and big would mean the chart is rendered bigger.

According to docs of keen-dataviz, It's better to control the size using the CSS of the container HTML element.
(While it's also possible to directly pass in {size: {width:..., height:xxx }}) to c3, it seems to only work for height, and not width.

Except we don't have access to the <div> directly in keen-react-charts.

I have tried adding two classNames through theme, e.g. theme="keen-dataviz my-own-class", but that seems to break the whole chart.

The solution could come in a variety of ways, but here are some I could see:

  1. Allow passing in a style prop to <Chart>, which will then be applied on the <div>
  2. Allow passing in a size prop to <Chart>, which will then be applied on the <div>
  3. Allow passing in multiple classNames as theme to <Chart>, which will then be applied on the <div>
  4. Allow passing in a id prop to <Chart>, which will then be applied on the <div>

Keen-Analysis dependency

Right now the keen-analysis is added as a devDependency so in result the user need to install it by his own.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.