Skip to content
Gravity Logo / Docs Gravity home
Browse documentation
Documentation/Gravity Native

Chart

Gravity Native charts are built on React Native SVG Charts with several modifications, so you can easily create beautiful charts in seconds.

There are three chart types available:

  1. Line chart
  2. Bar chart
  3. Pie chart

You can easily expand these with other chart types from the core library if you need more variety.

Code

<Chart 
  title='Revenue'
  type='line'
  legend
  data={ this.state.revenue }
  xAxis
  yAxis
  abbr
  height={ 200 } 
/>

Props

PropDescriptionRequiredValue
abbrabbreviate the values in labelsoptionalboolean
colorcolor of the chartoptionalred, blue (default), green, purple
dataformatted chart objectrequiredobject (see below)
heightchart heightrequiredinteger (default: 200)
legendshow the legendoptionalboolean
loadingtoggle the loading spinneroptionalboolean
titlechart titlerequiredstring
typetype of chart to displayrequiredline, bar, pie
xAxisshow or hide the x axisoptionalboolean
yAxisshow or hide the y axisoptionalboolean

Data Format

Chart data should be in the following format:

const data = {
labels: ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn'],
datasets: [{ label: 'Gravity', data: [3.7, 8.9, 9.8, 3.7, 23.1, 9.0] }]};

You can pass multiple datasets to a line or bar chart by adding to the datasets array.

There is a chart.create method located in server/helper/chart.js on the server that you can use to easily format chart data. Gravity Native will convert this format into the required format for React Native Charts so you can use one format for both Gravity Web and Gravity Native.

  const labels = 'User';
  const data = [

    { label: 'Owner', value: 7233 },
    { label: 'Admin', value: 321 },
    { label: 'User', value: 2101 }

  ];

  return chart.create(data, labels);