What is @elastic/charts?
@elastic/charts is a powerful charting library developed by Elastic. It provides a wide range of chart types and is designed to be highly customizable and performant. It is particularly well-suited for creating complex, data-driven visualizations in web applications.
What are @elastic/charts's main functionalities?
Line Chart
This code sample demonstrates how to create a simple line chart using @elastic/charts. The LineSeries component is used to define the data and the axes for the chart.
import { Chart, LineSeries, Settings } from '@elastic/charts';
const data = [
{ x: 0, y: 2 },
{ x: 1, y: 3 },
{ x: 2, y: 5 },
{ x: 3, y: 7 },
];
const LineChart = () => (
<Chart>
<Settings showLegend={true} legendPosition="right" />
<LineSeries
id="lineSeries"
xScaleType="linear"
yScaleType="linear"
xAccessor="x"
yAccessor="y"
data={data}
/>
</Chart>
);
Bar Chart
This code sample demonstrates how to create a bar chart using @elastic/charts. The BarSeries component is used to define the data and the axes for the chart.
import { Chart, BarSeries, Settings } from '@elastic/charts';
const data = [
{ x: 'A', y: 30 },
{ x: 'B', y: 80 },
{ x: 'C', y: 45 },
{ x: 'D', y: 60 },
];
const BarChart = () => (
<Chart>
<Settings showLegend={true} legendPosition="right" />
<BarSeries
id="barSeries"
xScaleType="ordinal"
yScaleType="linear"
xAccessor="x"
yAccessor="y"
data={data}
/>
</Chart>
);
Pie Chart
This code sample demonstrates how to create a pie chart using @elastic/charts. The Partition component is used to define the data and the structure of the pie chart.
import { Chart, Partition, Settings } from '@elastic/charts';
const data = [
{ category: 'A', value: 30 },
{ category: 'B', value: 80 },
{ category: 'C', value: 45 },
{ category: 'D', value: 60 },
];
const PieChart = () => (
<Chart>
<Settings showLegend={true} legendPosition="right" />
<Partition
id="pieChart"
data={data}
valueAccessor={(d) => d.value}
valueFormatter={(d) => `${d} %`}
layers={[
{
groupByRollup: (d) => d.category,
shape: {
fillColor: (d) => d.category === 'A' ? 'red' : 'blue',
},
},
]}
/>
</Chart>
);
Other packages similar to @elastic/charts
recharts
Recharts is a composable charting library built on React components. It is easy to use and provides a wide range of chart types. Compared to @elastic/charts, Recharts is more beginner-friendly but may lack some of the advanced customization options.
victory
Victory is another React-based charting library that offers a variety of chart types and is highly customizable. It is similar to @elastic/charts in terms of flexibility and customization but has a different API and design philosophy.
nivo
Nivo provides a rich set of dataviz components, built on top of D3 and React. It offers a wide range of chart types and is known for its beautiful and responsive charts. Nivo is comparable to @elastic/charts in terms of visual appeal and functionality.
Elastic Charts
🚨 WARNING While open source, the intended consumers of this repository are Elastic products. Read the FAQ for details.
You should check out our living style guide, which contains many examples on how charts look and feel, and how to use them in your products.
Installation
To install the Elastic Charts into an existing project, use the yarn
CLI (npm
is not supported).
yarn add @elastic/charts
Running Locally
Node
We depend upon the version of node defined in .nvmrc.
You will probably want to install a node version manager. nvm is recommended.
To install and use the correct node version with nvm
:
nvm install
Development environment
You can run the dev environment locally at http://localhost:9001 by running:
yarn
yarn start
We use storybook to document API, edge-cases, and the usage of the library.
A hosted version is available at https://elastic.github.io/elastic-charts.
Goals
The primary goal of this library is to provide reusable set of chart components that can be used throughout Elastic's web products.
As a single source of truth, the framework allows our designers to make changes to our look-and-feel directly in the code. And unit test coverage for the charts components allows us to deliver a stable "API for charts".
Contributing
You can find documentation around creating and submitting new features in CONTRIBUTING.md.
Wiki
Consumption
Documentation
License
Apache Licensed. Read the FAQ for details.