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

trading-charts

v0.2.3

Published

A lightweight trading chart library specially designed for small screens like mobile

Downloads

11

Readme

CandlestickChart

An open-source single-file JavaScript library for drawing candlestick charts.

NPM: https://www.npmjs.com/package/trading-charts

Basic Usage

Include the library:

<script src="CandlestickChart.js"></script>

Define an HTML div element as a parent for the chart. Please note that the position, width, and height style values of the div are overwritten, so you may want to wrap the div in another div for additional styling.

<div id="chart"></div>

Create the candlestick chart with the id of the div as the first argument and a second optional options argument (see below for all options):

var candlestickChart = new CandlestickChart( "chart" , {} );

Add a few candles:

for ( var i = 0 ; i < candles.length ; ++i )
{
    candlestickChart.addCandlestick( candles[i].timestamp , candles[i].open , candles[i].high , candles[i].low , candles[i].close );
}

And draw the chart:

candlestickChart.draw();

Updates

If you are using the chart to display live data that frequently updates you can use the updateCandlestick function. If a candle with the same timestamp already exists in the chart, it will be updated with the new values. If not, a new candle is added automatically.

candlestickChart.updateCandlestick( candlestick.timestamp , candlestick.open , candlestick.high , candlestick.low , candlestick.close );

Example

See the example.html file for a more detailed example.

Options

|Option|Description| |--|--| |overlayMode|Defines the behavior of the overlay. Possible values:| ||'click' - The overlay&crosshair only appear when the mouse or a finger is clicked. While the overlay is visible dragging the mouse or a finger moves the overlay. It can be hidden again with another click. Best for touch controls| ||'hover' - The overlay&crosshair are always visible and follow the mouse cursor. This best for mouse controls.| ||'none' - The overlay&crosshair are disabled| |disableGrid|Set to true to disable the grid| |disableLegend|Set to true to disable the legends| |disableCrosshair|Set to true to disable the crosshair| |disableLowHighPriceDisplay|Set to true to disable the low and high price markers in the chart| |disableCurrentMarketPrice|Set to true to disable the current market price overlay (i.e. the close price of the last candle)| |disablePanningAcceleration|Set to true to disable panning acceleration. When dragging the chart along the x-axis and letting go with some momentum, it will slowly decay if panning acceleration is enabled.| |allowOverPanning|When enabled you can pan the chart further into the empty space behind the last candle.|

General Chart Options

||| |--|--| |backgroundColor|The background color of the chart. E.g. '#222222'.| |font|The font used in the chart. Default 'sans-serif'.| |fontSize|The font size used in the chart. Default 12.| |decimalPlaces|The number of decimal places that all prices are rounded to. If no decimalPlaces option is specified, the chart will choose a sensible default value.| |marginLeft|The distance between the left edge of the canvas and the chart area.| |marginRight|The distance between the right edge of the canvas and the chart area.| |marginTop|The distance between the top edge of the canvas and the chart area.| |marginBottom|The distance between the bottom edge of the canvas and the chart area.| |watermarkImage|A url to a watermark image that is displayed in the center of the chart. You probably want to use a fairly transparent png image.|

Candle Options

||| |--|--| |greenColor|The color for green candles.| |redColor|The color for red candles.| |greenHoverColor|The color for green candles that are hovered or clicked.| |redHoverColor|The color for red candles that are hovered or clicked.| |wickWidth|The width of the wicks. Uneven numbers look better. Default 1.| |wickGreenColor|The color of the wick for green candles. By default this is the same green color as the candle's green color.| |wickRedColor|The color of the wick for red candles. By default this is the same red color as the candle's green color.| |candleBorderWidth|The border width of the candles. Default 0. If the candleBorderWidth is greater than 0, the border of the candle is drawn in the wickGreenColor&wickRedColor.|

Grid Options

||| |--|--| |xGridCells|How many grid cells are on the x-axis. Please note that this is only a rough estimate. The grid will automatically align to nice numbers.| |yGridCells|How many grid cells are on the y-axis. Please note that this is only a rough estimate. The grid will automatically align to nice numbers.| |gridLineStyle|The line style of the grid. Can either be 'dashed', 'dotted', or 'solid'.| |gridColor|The color of the grid lines.| |gridTextColor|The text color of the axis labels.|

Overlay Options

||| |--|--| |overlayBackgroundColor|The background color of the overlay.| |overlayTextColor|The text color of the overlay.| |overlayShowTime|When true the overlay will show the candle time. Default true.| |overlayShowData|When true the overlay will show the candle data. Default true.| |overlayShowChange|When true the overlay will show the change and percent change relative to the previous candle. Default true.|

Crosshair Options

||| |--|--| |crosshairColor|The color of the crosshair.| |crosshairTextColor|The text color of the crosshair markers on the axes.| |crosshairLineStyle|The line style of the crosshair. Can either be 'dashed', 'dotted', or 'solid'.| |crosshairLabelBackgroundColor|The background color of the crosshair labels. By default this is just the crosshair color.|

Market Price Options

||| |--|--| |marketPriceLineColor|The color of the current market price line.| |marketPriceTextColor|The text color of the current market price marker.| |marketPriceOpacity|The opacity of the market price background label. A value between 0 and 1, 0 being completely transparent and 1 complete opaque. Default 1.|

Control Options

||| |--|--| |scrollZoomSensitivity|The zoom sensitivity when using the mouse scroll wheel.| |touchZoomSensitivity|The zoom sensitivity when using touch controls and pinch to zoom.| |panningAccelerationDamping|If panning acceleration is enabled, this controls how fast the chart slows down. A value between 0 and 1. Default 0.975. Lower values will make the chart stop faster.|

Callback Functions

||| |--|--| |panningAtStartCallback()|Gets called when the chart is panned/scrolled along the x-axis and reaches the first candle. See example.html for an example implementation.| |panningAtEndCallback()|Gets called when the chart is panned/scrolled along the x-axis and reaches the last candle. See example.html for an example implementation.|