-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated README and little fixes. Add example
- Loading branch information
Mario
committed
Jun 11, 2021
1 parent
ac3242a
commit 3506960
Showing
7 changed files
with
138 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,90 @@ | ||
# Charty, a small library for pie and circle charts | ||
# Charty, a small library for charts | ||
|
||
Charty is a simple library to draw pie and circle charts. | ||
Charty is a simple library to draw pie and circle 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](charty.png) | ||
|
||
## How to start using. | ||
|
||
```javascript | ||
const chart = new Charty({}) //for a empty chart | ||
|
||
const chart = new Charty({ //With options, every one is optionl but data | ||
title: 'My Chart', //The title of the chart | ||
chartType: 'circle', //The type of chart, circle 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 float numbers | ||
selector: '#app' //Where the chart will be inserted, must be a valid css selector (default to body) | ||
}) | ||
``` | ||
|
||
|
||
|
||
## Add aditional data | ||
|
||
The charts accept insert additional data with the next function: | ||
|
||
```javascript | ||
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 throught the ID of the chart, every chart have a data-chart-id attribute, and every chart hav a unique ID. | ||
|
||
```javascript | ||
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's 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` function. | ||
|
||
```javascript | ||
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 donate a small amount in thankfulness trought [Paypal](https://www.paypal.com/donate?hosted_button_id=NZ9Z8YDHSMMEC&source=url) :smile: | ||
|
||
<form action="https://www.paypal.com/donate" method="post" target="_top"> | ||
<input type="hidden" name="hosted_button_id" value="NZ9Z8YDHSMMEC" /> | ||
<input type="image" src="https://www.paypalobjects.com/es_XC/i/btn/btn_donate_SM.gif" border="0" name="submit" title="PayPal - The safer, easier way to pay online!" alt="Donate with PayPal button" /> | ||
<img alt="" border="0" src="https://www.paypal.com/es_MX/i/scr/pixel.gif" width="1" height="1" /> | ||
</form> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Charty</title> | ||
<link rel="stylesheet" href="../charty.css"> | ||
<style> | ||
body{ | ||
font: 16px/1.6 system-ui; | ||
display: grid; | ||
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); | ||
gap: 1rem; | ||
margin-top: 8rem; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<script src="../charty.js"></script> | ||
<script src="main.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
const chart = new Charty({ | ||
title: 'Circle chart', | ||
data: [ | ||
{Stone: 24}, | ||
{Wood: 7}, | ||
{Steel: 29} | ||
] | ||
}); | ||
|
||
const all = new Charty({ | ||
title: 'Pie Chart', | ||
data: [ | ||
{All: 38} | ||
], | ||
chartType: 'pie' | ||
}); | ||
|
||
const ages = new Charty({ | ||
title: 'Ages', | ||
data: [ | ||
{'18 - 25': 30}, | ||
{'26 - 35': 45}, | ||
{'36 - 45': 27}, | ||
{'45 - 55': 17} | ||
] | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.