layerchart
Composable Svelte chart components to build a large variety of visualizations
Top Related Projects
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
Open-source JavaScript charting library behind Plotly and Dash
Simple HTML5 Charts using the <canvas> tag
Highcharts JS, the JavaScript charting framework
📊 Interactive JavaScript Charts built on SVG
📊 Re-usable, easy interface JavaScript chart library based on D3.js
Quick Overview
LayerChart is a JavaScript library for creating interactive, layered charts using HTML5 canvas. It allows developers to build complex, multi-layered visualizations with ease, supporting various chart types and customizable styling options.
Pros
- Flexible and customizable, allowing for creation of complex, multi-layered charts
- Efficient rendering using HTML5 canvas for smooth performance
- Supports multiple chart types and data series in a single visualization
- Provides interactive features like zooming, panning, and tooltips
Cons
- Limited documentation and examples available
- Smaller community compared to more established charting libraries
- May have a steeper learning curve for beginners
- Lacks built-in responsiveness for different screen sizes
Code Examples
Creating a basic line chart:
const chart = new LayerChart({
canvas: document.getElementById('myChart'),
width: 800,
height: 400
});
chart.addLayer(new LineLayer({
data: [1, 3, 2, 4, 3, 5],
color: 'blue'
}));
chart.render();
Adding multiple layers to a chart:
const chart = new LayerChart({
canvas: document.getElementById('myChart'),
width: 800,
height: 400
});
chart.addLayer(new LineLayer({
data: [1, 3, 2, 4, 3, 5],
color: 'blue'
}));
chart.addLayer(new BarLayer({
data: [2, 4, 3, 5, 4, 6],
color: 'green'
}));
chart.render();
Customizing chart appearance:
const chart = new LayerChart({
canvas: document.getElementById('myChart'),
width: 800,
height: 400,
margin: { top: 20, right: 20, bottom: 30, left: 40 },
backgroundColor: '#f0f0f0'
});
chart.addLayer(new LineLayer({
data: [1, 3, 2, 4, 3, 5],
color: 'red',
lineWidth: 2,
pointRadius: 4
}));
chart.render();
Getting Started
To use LayerChart in your project, follow these steps:
-
Include the LayerChart library in your HTML file:
<script src="https://unpkg.com/layerchart/dist/layerchart.min.js"></script>
-
Create a canvas element in your HTML:
<canvas id="myChart"></canvas>
-
Initialize and render a chart in your JavaScript:
const chart = new LayerChart({ canvas: document.getElementById('myChart'), width: 800, height: 400 }); chart.addLayer(new LineLayer({ data: [1, 3, 2, 4, 3, 5], color: 'blue' })); chart.render();
Competitor Comparisons
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
Pros of d3
- Extremely powerful and flexible, capable of creating a wide range of complex visualizations
- Large and active community, extensive documentation, and numerous examples available
- Supports a wide range of data formats and can handle large datasets efficiently
Cons of d3
- Steep learning curve, especially for those new to data visualization or JavaScript
- Requires more code and setup for basic charts compared to higher-level libraries
- Lower-level API can make simple visualizations more time-consuming to create
Code Comparison
d3:
const svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
svg.selectAll("rect")
.data(data)
.enter().append("rect")
.attr("x", (d, i) => i * 30)
.attr("y", d => height - d * 4)
.attr("width", 25)
.attr("height", d => d * 4);
layerchart:
const chart = new LayerChart({
layers: [
new BarLayer({
data: data,
x: d => d.category,
y: d => d.value
})
]
});
chart.render();
This comparison highlights the difference in abstraction level between d3 and layerchart. While d3 provides fine-grained control over every aspect of the visualization, layerchart offers a more high-level API for creating common chart types with less code.
Open-source JavaScript charting library behind Plotly and Dash
Pros of Plotly.js
- Extensive library with a wide range of chart types and customization options
- Large community support and regular updates
- Built-in interactivity features like zooming, panning, and hover tooltips
Cons of Plotly.js
- Larger file size and potentially slower performance for complex visualizations
- Steeper learning curve due to its extensive API and configuration options
- May be overkill for simple chart requirements
Code Comparison
LayerChart:
const chart = new LayerChart({
layers: [
new BarLayer({ data: barData }),
new LineLayer({ data: lineData })
]
});
Plotly.js:
Plotly.newPlot('chart', [{
type: 'bar',
x: barData.x,
y: barData.y
}, {
type: 'scatter',
x: lineData.x,
y: lineData.y
}]);
Summary
LayerChart focuses on composing layers for custom visualizations, while Plotly.js offers a comprehensive charting solution with built-in chart types. LayerChart may be more suitable for specific, performance-critical use cases, whereas Plotly.js excels in providing a wide range of out-of-the-box charting options with extensive customization capabilities.
Simple HTML5 Charts using the <canvas> tag
Pros of Chart.js
- Extensive documentation and large community support
- Wide range of chart types and customization options
- Built-in responsiveness and animation features
Cons of Chart.js
- Larger file size and potentially slower performance for complex visualizations
- Less flexibility for creating custom, non-standard chart types
- Steeper learning curve for advanced customizations
Code Comparison
LayerChart:
import { LayerCake, Svg } from 'layercake';
import Line from './Line.svelte';
const chart = new LayerCake({
data: myData,
x: d => d.x,
y: d => d.y
});
Chart.js:
import Chart from 'chart.js/auto';
const ctx = document.getElementById('myChart');
new Chart(ctx, {
type: 'line',
data: myData,
options: { /* ... */ }
});
LayerChart focuses on a modular, component-based approach using Svelte, while Chart.js provides a more traditional, configuration-based setup. LayerChart offers greater flexibility for custom visualizations, but Chart.js excels in ease of use for standard chart types and built-in features.
Highcharts JS, the JavaScript charting framework
Pros of Highcharts
- Extensive documentation and examples
- Wide range of chart types and customization options
- Strong community support and regular updates
Cons of Highcharts
- Commercial license required for most use cases
- Steeper learning curve due to its comprehensive feature set
- Larger file size, which may impact page load times
Code Comparison
Layerchart:
import { LineChart } from 'layerchart';
const chart = new LineChart('#chart', {
data: [/* ... */],
x: d => d.date,
y: d => d.value
});
Highcharts:
Highcharts.chart('container', {
series: [{
type: 'line',
data: [/* ... */]
}],
xAxis: { type: 'datetime' },
yAxis: { title: { text: 'Value' } }
});
Key Differences
- Layerchart focuses on simplicity and ease of use, while Highcharts offers more advanced features
- Highcharts provides built-in responsiveness and cross-browser compatibility
- Layerchart is open-source and free to use, whereas Highcharts requires a license for commercial use
- Highcharts has a larger ecosystem with plugins and extensions
Use Cases
- Layerchart: Ideal for quick, simple charts in web applications
- Highcharts: Better suited for complex, interactive visualizations in enterprise environments
📊 Interactive JavaScript Charts built on SVG
Pros of ApexCharts.js
- More comprehensive and feature-rich charting library
- Extensive documentation and examples
- Wider range of chart types and customization options
Cons of ApexCharts.js
- Larger file size and potentially heavier performance impact
- Steeper learning curve due to more complex API
Code Comparison
LayerChart:
import { LineChart } from 'layerchart';
const chart = new LineChart({
data: [1, 2, 3, 4, 5],
container: '#chart'
});
ApexCharts.js:
import ApexCharts from 'apexcharts';
const options = {
series: [{ data: [1, 2, 3, 4, 5] }],
chart: { type: 'line' }
};
const chart = new ApexCharts(document.querySelector("#chart"), options);
chart.render();
LayerChart offers a simpler API for basic charts, while ApexCharts.js provides more configuration options but requires more setup code. ApexCharts.js is better suited for complex visualizations and projects requiring a wide variety of chart types, while LayerChart may be preferable for simpler use cases or projects prioritizing lightweight dependencies.
📊 Re-usable, easy interface JavaScript chart library based on D3.js
Pros of billboard.js
- More comprehensive and feature-rich charting library with a wider variety of chart types
- Extensive documentation and examples, making it easier for developers to get started
- Larger community and more frequent updates, potentially leading to better support and bug fixes
Cons of billboard.js
- Larger file size and potentially heavier performance impact due to its comprehensive nature
- Steeper learning curve for developers who only need basic charting functionality
- Less flexibility for custom, low-level chart implementations compared to LayerChart's approach
Code Comparison
billboard.js:
var chart = bb.generate({
data: {
columns: [
["data1", 30, 200, 100, 400, 150, 250],
["data2", 50, 20, 10, 40, 15, 25]
],
type: "line"
}
});
LayerChart:
const chart = new Chart({
layers: [
new LineLayer({
data: [30, 200, 100, 400, 150, 250],
color: 'blue'
}),
new LineLayer({
data: [50, 20, 10, 40, 15, 25],
color: 'red'
})
]
});
Both libraries offer ways to create charts, but billboard.js provides a more declarative approach with built-in chart types, while LayerChart focuses on composing charts from individual layers, offering more granular control over chart elements.
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
LayerChart
A large collection of composable Svelte chart components to build a wide range of visualizations
- Cartesian (Bar, Area, Stack, Scatter)
- Radial (Pie, Arc, Sunburst)
- Hierarchy (Pack, Tree, Treemap, Sunburst)
- Graph (Sankey)
- Geo (Choropleth, Spike, Bubble, Point, Globe)
Interactions
- Tooltip, Highlights, Pan/Zoom
SVG
- Basic (Arc, Circle, Group, Line, Spline, Text)
- Gradients and Patterns
- ClipPath
- Multi-line text
Others
- Legends including ColorRamps
See also the companion library Svelte UX for a large collection of components, actions, stores, and utilities to build highly interactive applications.
Contributing
Install dependencies
pnpm i
Run dev server for layerchart
package
cd packages/layerchart
pnpm dev
Add changeset to include change in changelog and determine next version
pnpm changeset
Community
Join the Discord server to ask questions, find collaborators, or just say hi!
Top Related Projects
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
Open-source JavaScript charting library behind Plotly and Dash
Simple HTML5 Charts using the <canvas> tag
Highcharts JS, the JavaScript charting framework
📊 Interactive JavaScript Charts built on SVG
📊 Re-usable, easy interface JavaScript chart library based on D3.js
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