HomeOur TeamContact

Bar Chart

By Utkarsh Lubal
Published in Charts
June 13, 2022
1 min read
Bar Chart

Table Of Contents

01
Chart-Kit
02
Expo snack preview
03
Installation
04
Example
05
Tutorial
06
Live preview and edit

Chart-Kit

React-native-chart is a simple module for adding line charts, area charts, or bar charts to your React Native app.

Expo snack preview

https://snack.expo.dev/@sam042/awesome-react-native---bar-chart

Installation

npm i react-native-chart-kit --save

Example

import React from 'react';
import {
  SafeAreaView,
  Text,
  View,
  StyleSheet,
  Dimensions,
  ScrollView,
} from 'react-native';
import { BarChart } from 'react-native-chart-kit';

const MyBarChart = () => {
  return (
    <>
      <Text style={styles.header}>Bar Chart</Text>
      <BarChart
        data={{
          labels: ['January', 'February', 'March', 'April', 'May', 'June'],
          datasets: [
            {
              data: [20, 45, 28, 80, 99, 43],
            },
          ],
        }}
        width={Dimensions.get('window').width - 16}
        height={220}
        yAxisLabel={'Rs'}
        chartConfig={{
          backgroundColor: '#1cc910',
          backgroundGradientFrom: '#eff3ff',
          backgroundGradientTo: '#efefef',
          decimalPlaces: 2,
          color: (opacity = 1) => `rgba(0, 0, 0, ${opacity})`,
          style: {
            borderRadius: 16,
          },
        }}
        style={{
          marginVertical: 8,
          borderRadius: 16,
        }}
      />
    </>
  );
};

const App = () => {
  return (
    <SafeAreaView style={{flex: 1}}>
      <ScrollView>
        <View style={styles.container}>
          <View>
                  <MyBarChart />
          </View>
        </View>
      </ScrollView>
    </SafeAreaView>
  );
};

export default App;

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: 'white',
    justifyContent: 'center',
    alignItems: 'center',
    textAlign: 'center',
    padding: 10,
  },
  header: {
    textAlign: 'center',
    fontSize: 18,
    padding: 16,
    marginTop: 16,
  },
});

Tutorial

Live preview and edit


Tags

chartgraph
Previous Article
Bottom half modal
Next Article
Stacked Bar Chart
Utkarsh Lubal

Utkarsh Lubal

Full Stack Developer

Related Posts

Line Chart
Line Chart
June 13, 2022
1 min

Quick Links

Advertise with usAbout UsContact Us

Social Media