Top Related Projects
Simple HTML5 Charts using the <canvas> tag
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
nivo provides a rich set of dataviz components, built on top of the awesome d3 and React libraries
Simple, responsive, modern SVG Charts with zero dependencies
Quick Overview
Peity is a lightweight jQuery plugin that converts HTML elements into small inline charts. It supports pie, donut, line, and bar charts, making it easy to add simple data visualizations to web pages without the need for complex charting libraries.
Pros
- Extremely lightweight (4KB minified and gzipped)
- Easy to use with minimal configuration required
- Supports responsive design and updates charts on window resize
- Customizable with options for colors, size, and chart-specific settings
Cons
- Limited to basic chart types (pie, donut, line, and bar)
- Requires jQuery, which may not be ideal for modern projects
- Lacks advanced features found in more comprehensive charting libraries
- Not actively maintained (last update was in 2018)
Code Examples
Creating a simple pie chart:
<span class="pie">3/5</span>
<script>
$(".pie").peity("pie");
</script>
Customizing a line chart:
<span class="line">5,3,9,6,5,9,7,3,5,2</span>
<script>
$(".line").peity("line", {
width: 64,
height: 32,
stroke: "#7cb5ec",
fill: "#e6f2fa"
});
</script>
Updating a bar chart dynamically:
<span class="bar">5,3,9,6,5,9,7,3,5,2</span>
<script>
var updatingChart = $(".bar").peity("bar", {
width: 100,
height: 40
});
setInterval(function() {
var random = Math.round(Math.random() * 10);
var values = updatingChart.text().split(",");
values.shift();
values.push(random);
updatingChart
.text(values.join(","))
.change();
}, 1000);
</script>
Getting Started
- Include jQuery and Peity in your HTML file:
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/peity/3.3.0/jquery.peity.min.js"></script>
- Add HTML elements with data:
<span class="pie">3/5</span>
<span class="donut">5,2,3</span>
<span class="line">5,3,9,6,5,9,7,3,5,2</span>
<span class="bar">5,3,9,6,5,9,7,3,5,2</span>
- Initialize Peity charts:
$(".pie").peity("pie");
$(".donut").peity("donut");
$(".line").peity("line");
$(".bar").peity("bar");
Competitor Comparisons
Simple HTML5 Charts using the <canvas> tag
Pros of Chart.js
- More comprehensive and feature-rich, offering a wide variety of chart types
- Highly customizable with extensive documentation and community support
- Responsive and mobile-friendly with built-in animation capabilities
Cons of Chart.js
- Larger file size and potentially higher performance overhead
- Steeper learning curve due to its extensive API and configuration options
- May be overkill for simple, inline charts or sparklines
Code Comparison
Peity (simple inline chart):
$(".pie").peity("pie");
Chart.js (basic pie chart):
new Chart(ctx, {
type: 'pie',
data: {
labels: ['Red', 'Blue', 'Yellow'],
datasets: [{
data: [300, 50, 100]
}]
}
});
Summary
Peity is ideal for small, inline charts with minimal configuration, while Chart.js offers a more robust solution for complex, interactive visualizations. Peity excels in simplicity and lightweight implementation, whereas Chart.js provides greater flexibility and features at the cost of increased complexity and file size. The choice between the two depends on the specific requirements of the project, such as the level of customization needed and the complexity of the data being visualized.
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
Pros of d3
- Highly versatile and powerful for creating complex, interactive data visualizations
- Extensive documentation and large community support
- Offers fine-grained control over every aspect of the visualization
Cons of d3
- Steeper learning curve due to its complexity and extensive API
- Larger file size, which may impact page load times
- Requires more code to create even simple charts or graphs
Code Comparison
d3:
const svg = d3.select("body").append("svg")
.attr("width", 200)
.attr("height", 100);
svg.selectAll("circle")
.data([32, 57, 112])
.enter().append("circle")
.attr("cy", 60)
.attr("cx", (d, i) => i * 100 + 30)
.attr("r", d => Math.sqrt(d));
Peity:
$(".pie").peity("pie");
$(".line").peity("line");
$(".bar").peity("bar");
Summary
d3 is a comprehensive data visualization library offering extensive capabilities and customization options, but with a steeper learning curve. Peity, on the other hand, is a lightweight library focused on creating simple, inline charts with minimal code. d3 is better suited for complex, interactive visualizations, while Peity excels at quick, simple charts integrated directly into text or tables.
nivo provides a rich set of dataviz components, built on top of the awesome d3 and React libraries
Pros of nivo
- More comprehensive and feature-rich charting library
- Supports a wider variety of chart types and customization options
- Built with React and D3, offering modern and interactive visualizations
Cons of nivo
- Larger package size and potentially higher learning curve
- May be overkill for simple, lightweight chart needs
- Requires React, which might not be suitable for all projects
Code Comparison
nivo example (React):
import { ResponsivePie } from '@nivo/pie'
const MyPieChart = ({ data }) => (
<ResponsivePie
data={data}
margin={{ top: 40, right: 80, bottom: 80, left: 80 }}
innerRadius={0.5}
padAngle={0.7}
cornerRadius={3}
/>
)
Peity example (jQuery):
$(".pie").peity("pie", {
fill: ["#ff9900", "#fff4dd", "#ffd592"],
radius: 50
});
Summary
nivo is a more powerful and versatile charting library, offering a wide range of chart types and customization options. It's built with modern web technologies and provides interactive visualizations. However, it comes with a larger package size and may be more complex to implement.
Peity, on the other hand, is a simpler and lightweight library focused on small, inline charts. It's easier to use for basic charting needs but lacks the advanced features and flexibility of nivo. Peity is also jQuery-dependent, which may not be ideal for all projects.
Simple, responsive, modern SVG Charts with zero dependencies
Pros of Charts
- More comprehensive charting library with a wider variety of chart types
- Active development and maintenance, with regular updates and improvements
- Better documentation and examples for easier implementation
Cons of Charts
- Larger file size and potentially higher performance overhead
- Steeper learning curve due to more complex API and configuration options
- May be overkill for simple visualization needs
Code Comparison
Peity:
$(".pie").peity("pie");
$(".bar").peity("bar");
Charts:
const chart = new frappe.Chart("#chart", {
data: {
labels: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
datasets: [{ values: [18, 40, 30, 35, 8, 52, 17] }]
},
type: 'bar'
});
Summary
Peity is a lightweight, simple charting library ideal for inline visualizations, while Charts offers a more robust set of features for creating complex, interactive charts. Peity excels in simplicity and ease of use, whereas Charts provides greater flexibility and customization options at the cost of increased complexity and resource usage.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Peity
Peity (sounds like deity) is a jQuery plugin that converts an element's content into a mini <svg>
pie, donut, line or bar chart.
Basic Usage
HTML
<span class="pie">3/5</span>
<span class="donut">5,2,3</span>
<span class="line">3,5,1,6,2</span>
<span class="bar">2,5,3,6,2,1</span>
JavaScript (jQuery)
$(".pie").peity("pie");
$(".donut").peity("donut");
$(".line").peity("line");
$(".bar").peity("bar");
Docs
More detailed usage can be found at benpickles.github.io/peity.
Development
Run the automated tests with:
npm test
To manually view all test cases run:
make server
And hit http://localhost:8080/.
Release
Update the version string in jquery.peity.js
, run make release
, and follow the instructions.
Copyright
Copyright 2009-2020 Ben Pickles. See LICENCE for details.
Top Related Projects
Simple HTML5 Charts using the <canvas> tag
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
nivo provides a rich set of dataviz components, built on top of the awesome d3 and React libraries
Simple, responsive, modern SVG Charts with zero dependencies
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot