Giter VIP home page Giter VIP logo

charty's Introduction

Charty, a small library for charts

Charty is a simple library to draw pie and donut charts. Just that, simple to use.

To use it, just link de library with <script src="charty.js"> and between the <header> tag link the css file <link rel="stylesheet" rel="charty.css" (you can define your own css).

Charty Example

How to start using it.

const chart = new Charty({}) 	//for an empty chart(withe examle data)

const chart = new Charty({ 		//With options, everyone is optional except data
    title: 'My Chart',			//The title of the chart
    chartType: 'circle',		//The type of chart, circle(donut) or pie
    data: [						//An array of objects int he format name/value
        {Apples: 45},			//{Name: Value}
        {Oranges: 37},
        {Bananas: 52}
    ],
    precision: false,		//If the data chart have decimal numbers(just two)
    selector: '#app'		//Where the chart will be inserted, must be a valid css selector (default to body)
})

Add additional data

The charts accept insert additional data with the next method:

chart.addData({"Name", Value}) //Name: String, Value: Integer

The chart will be redrawn after insert data

Manipulate the chart

If you want to manipulate the chart's DOM, you can do it through the ID of the chart, every chart have a data-chart-id attribute, and every chart have a unique ID.

const DIV = document.querySelector(`[data-chart-id="${chart.id}"]`)
//Remove the background gradient
DIV.style.backgroundImage = 'none'
//The background will be changed
DIV.style.backgroundColor = 'lightyellow'

By default the charts have a light gradient

Change chart colors

By default the colors are static, if you want to change they, yo must edit the file charty.js and change the colors array in the getColor method.

getColor(index) {
    const colors = [
      'purple', //Change these colors
      'midnightblue',
      'blue',
      'cyan',
      'magenta',
      'yellow',
      'dimgray',
      'orange',
      'brown',
      'indigo',
      'pink',
      'gold'
    ];
    return colors[index];
  };

If this small library is useful for you or liked you, consider to buy a me a coffee โ˜• (or pizza ๐Ÿ• ๐Ÿ˜ƒ)

charty's People

Contributors

max131 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

davgit stmorand

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.