Skip to main content

A Dash Component library for ChartJs.

Project description

Dash Chartjs Component

Chart.js is one the most popular javascript charting library. Dash Chartjs Component is a Dash component library that renders ChartJs React component inside Dash App.

Installation

pip install dash-chartjs

Prop List

id (str): The ID used to identify this component in Dash callbacks.

type (str): Chart.js chart type.

data (dict): The data object that is passed into the Chart.js chart.

options (dict): The options object that is passed into the Chart.js chart.

toolbox (boolean): Toolbox with reset and download buttons for chart.

linearGradientList (list): List of colors for the Linear Gradient.

linearGradientDirection (str): Set the direction of Linear Gradient. Either 'horizontal' or 'vertical'. Vertical is default.

useGradient (str): Apply Linear Gradient on 'borderColor', 'backgroundColor' or on 'both'. Applies on both by default.

customCanvasBackgroundColor (str): Set the Background color of Canvas.

clickData (dict): clickData returns the datasetIndex and index of data point clicked.

style (dict): Defines CSS styles which will override styles previously set.

Additional Plugins Integrated

chartjs-plugin-zoom

Basic Configuration

'options': {
    'plugins': {
      'zoom': {
        'zoom': {
          'wheel': {
            'enabled': True,
          },
          'pinch': {
            'enabled': True
          },
          'mode': 'xy',
        }
      }
    }
}

chartjs-plugin-datalabels

Basic Configuration

'options': {
  'plugins': {
    # Change options for ALL labels of THIS CHART
    'datalabels': {
      'color': '#36A2EB'
    }
  }
},
'data': {
  'datasets': [{
    # Change options only for labels of THIS DATASET
    'datalabels': {
      'color': '#FFCE56'
    }
  }]
}

Example datalables

chartjs-plugin-annotation

Basic Configuration

'options': {
  'plugins': {
    'annotation': {
      'annotations': {
        'box1': {
          # Indicates the type of annotation
          'type': 'box',
          'xMin': 1,
          'xMax': 2,
          'yMin': 50,
          'yMax': 70,
          'backgroundColor': 'rgba(255, 99, 132, 0.25)'
        }
      }
    }
  }
}

Example annotations

Basic Usage

from dash import dash,html
import pandas as pd
from dash_chartjs import ChartJs

app = dash.Dash(__name__,meta_tags=[{"name": "viewport", "content": "width=device-width, initial-scale=1"}])

df = pd.read_csv('https://raw.githubusercontent.com/JetBlack101/visitors-to-georgia-ts-analysis/main/Data/VisitorsToGeorgia_2011-2019.csv')

df['Date'] = pd.to_datetime(df['Date'])

x = df['Date']
y = df['Visitors']

data = {
    'labels': x,
    'datasets': [{
        'label': 'Visitors to Georgia',
        'data': y,
        'fill':'false',
        'borderColor': 'rgb(75, 192, 192)',
        'tension': 0.1
    }]
}
options = {
    'scales': {
        'x': {
            'type':'time'
        }
    },
    'plugins':{
        'zoom':{
            'zoom':{
                'wheel':{
                    'enabled': True
                },
            'mode':'xy'
            }
        }
    } 
}


app.layout = html.Div(
    [
        ChartJs(type='line',data=data,options=options)
    ]
)

if __name__ == '__main__':
    app.run_server(debug=False)

Demo

https://user-images.githubusercontent.com/31138706/192035295-0a10eb80-0881-443b-8ea8-7dfd98eb77f3.mp4

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dash_chartjs-0.0.8.tar.gz (176.1 kB view details)

Uploaded Source

File details

Details for the file dash_chartjs-0.0.8.tar.gz.

File metadata

  • Download URL: dash_chartjs-0.0.8.tar.gz
  • Upload date:
  • Size: 176.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for dash_chartjs-0.0.8.tar.gz
Algorithm Hash digest
SHA256 1c74785413a2dc5af2d5ec5600df72cef2c720f5f7ff0517c0e57eafd90762aa
MD5 ff6efe11f17a9242ac77bc7dcdb6da06
BLAKE2b-256 4fdc792522311e1baab72c9a1941045fcaa83d39512d4142a5da19c19038b6d9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page