npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

common-charts-js

v1.0.1

Published

The most common charts in data visualization graphs such as line, bar, pie and more are pre built using D3.js for re usability.

Downloads

3

Readme

common-charts-js

By José Martínez Santana

Technologies used

Description

D3, the short name for Data-Driven Documents, is a JavaScript library for manipulating documents based on data. D3 helps to bind data to HTML, SVG and CSS. It provides a wide range of tools and functions that enable developers to create interactive and dynamic data visualizations.

common-charts-js solves the problem re write again and again the same code for the common data visualization charts (like line 📈, bar 📊, etc.). This is a library which has prebuild charts using the Object Oriented Programming classes of ECMAScript 6. The user only needs to import the class chart and provide the parameters to create it. In addition if the user knows D3, it is possible to customize more any of the pre build chart.

Charts at disposal

The library has the next charts in the current version:

  1. Line (single and multi series).
  2. Bar (simple, grouped, stacked and normalized).
  3. Area (single and multi series).
  4. Slope.
  5. Radar.

Installation

  1. Install NodeJS on your computer.
  2. Create a folder for your project.
  3. Execute the next command in the terminal:
npm i -S common-charts-js

Usage

How to download D3 library

This library do not use the npm install d3 to avoid the unnecessary loading js files of the whole D3 library.

In order to download D3 the lastest version and use it in a vanilla HTML in modern browsers, import D3 from jsDelivr or unpkg or another CDN.

Example of the import in the HTML script tag

<script src="https://d3js.org/d3.v7.js" type="text/javascript" charset="utf-8"></script>

How initialize a chart

  1. Create a HTML file. Add the D3 library, add svg element where the chart will be contained. Finally at a script tag of your code.
<!DOCTYPE html>
<html>
  <head>
    <script src="https://unpkg.com/[email protected]/dist/d3.min.js" type="text/javascript"></script>
    <title>Common charts example</title>
  </head>
  <body>
    <h1>Example of how to use the common-charts-js library</h1>
    <svg class="chart"></svg>
    <script type="module" src="./firstgraph.js"></script>
  </body>
</html>
  1. Create a file called firstgraph.js. Inside it, import the desired chart to be displayed. The common-charts-js library. They were written using the ECMACScript 6 modules. For example the multi line series graph.
import { MultiLineGraph }  from "common-charts-js";
  1. Create or fetch a data source. Data always needs to be an array of JSON format structure with the independent variable and depend variable(s). The library will take care of creating a detailed data structure for binding the data to the svg elements. For example, graph the next mathematical function: $$y = f(x) = x^2$$
const data /**@type {Array<{ x: number, y: number }>}*/ = [
    {x: 1, y: 1},
    {x: 2, y: 4},
    {x: 3, y: 9},
    {x: 4, y: 16},
    {x: 5, y: 25},
    {x: 6, y: 36},
    {x: 7, y: 49},
    {x: 8, y: 64},
    {x: 9, y: 81},
    {x: 10, y: 100}
];
  1. Initalize the imported class of the MultiLineGraph. For more details, see the documentation.
const graph = new MultiLineGraph({
  rawData: data,
  svgSelector: "svg.chart",
  independentSerie: "x",
  dependentSeries: ["y"],
  independentScale: d3.scaleLinear(),
  dependentScale: d3.scaleLinear(),
  colorScale: d3.scaleOrdinal().range(schemeSet2),
  independentAxis: d3.axisBottom(),
  dependentAxis: d3.axisLeft(),
});
  1. Start to draw the chart in the svg container of the HTML document.
graph.renderSeries();
graph.renderIndependentAxis();
graph.renderDependentAxis();

Limitations

Neither the common-chart-js and D3 are libraries for complex data cleaning. The recommended use of them are with cleaned semi structured data previously processed with another tool such as Ms Excel or Pandas for Python or any other software for data manipulation.

The user must have some previous knowledge about how to use D3 in order to select the correct scales and axis to build the chart.

The common-chart-js code works only in D3 version 4 or above.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. I invite you to collaborate directly in this repository: common-charts-js

License

common-charts-js is released under the MIT License.