MilliChart_v3

Description

Interactive HTML5 chart with the following features:

Required files

milli_chart_v3.js
milli_widget_api.js

If run from npm, these files are included in the package.

Settings

setting type valid value (default) description
adjusted boolean true/false (true) wether to adjust the timeseries for corporateactions
absoluteScaling boolean true/false (false) set to true to do absolute compares
autodraw boolean true/false (true) show the chart be drawn automatically, you will need to call drawWidget in your code if not
chartlen string 0-20d,1-12m,1-10y,max,ytd (1d) which chart to show when drawing (ytd = year to date, 0d,1d = both show today but 0d doesn't scale on open/close time)
chartStyle object List of valid settings Set styling of chart
closePriceIndicator boolean false/string (false) set to color to enable the closeprice indicator line f ex #ff0000
compare1Style object List of valid settings Set styling of chartline for first compare
compare2Style object List of valid settings Set styling of chartline for second compare
compare3Style object List of valid settings Set styling of chartline for third compare
compress numeric 1 - 60 (1) aggregate trades per x minutes
curveOnTop boolean true/false (true) set to True to draw the chartline (and fill) over labels inside the chart
dateformat string yyyy-mm-dd, yy-mm-dd, b dd, b dd yyyy, dd/mm, d/m, yyyy-mm-dd d mmm (yyyy-mm-dd) format dates on datetime legend
drawxaxis boolean true/false (true) whether to draw the x-axis line
drawyaxis boolean true/false (true) whether to draw the y-axis line, does not work with false atm
drawy2axis boolean true/false (false) whether to draw the y2-axis line , performance numbers
enablezoom boolean true/false (true) whether to allow zooming the chart
fields array (strings) List of valid values to add to the datarequest insref,name,tradecurrency, price and quantity is always included
fillchart boolean true/false (false) whether to fill the priced graph area
gridHorizontalLines boolean true/false (true) whether to draw the horizontal gridlines
gridHorizontalLinesStyle string dash/line (line) if dash horizontal lines will be dashed (3,3)
gridVerticalLines boolean true/false (true) whether to draw the vertical gridlines
gridVerticalLinesStyle string dash/line (line) if dash horizontal lines will be dashed(3,3) (day changes in intrady charts will be dashed)
hcurv boolean true/false (false) draw connecting lines vertically (mostly used for interest rates)
historylen string 1-12m ,1-10y, max (required if historical chart should be shown) amount of history to fetch (xw, xm,xy) where x is numeric
horizontalLegendStyle object List of valid settings Set styling of horzontal legend text
horizontalGridStyle object List of valid settings Set styling of horizontal gridlines
indicators array Array of objects containing List of valid indicators Add indicators to chart.
instrument array / numeric entitled instrument (required) instrument and up to 3 compares to draw, can be an insref or an array of up to 4 insrefs
instrumentStyle object List of valid settings Set styling of chartline
intradayDatePos object Object description Settings describing how dates should be drawn in intraday charts
intradaylen numeric 1-20 (required if intraday chart should be shown) days of trades to fetch
nochartlabel string any text (No data to draw on) text to show when there is no data to draw on current interval
onreadyCallback function valid function function to be called when the chart is drawn
previousDayClose boolean true/false (true) adds previous day closeprice to intradaycharts
priceIndicator boolean true/false (false) (Priceindicator details) adds a div with lastprice on the righthand legend if present
pricetype string price/yield/nav (undefined) pricetype to request data for, if undefined the data api will use instrument default
streaming bolean or object false/valid streaming api object (false) false if no streaming, a MilliStream object if not
target element target div (required) target div for the chart ("postion:relative" required on this
timeformat string HH:mm,hh:mm,h:mm,h:mm:ss,HH:mm:ss (HH:mm:ss) format times on datetime legend
tooltip object object with "formatter" (Tooltip details) set to format tooltip on mouseover, default is undefined and will disable tooltip
token string valid token (required) entitlement token
verticalLegendStyle object List of valid settings Set styling of vertical legend text (Price legend)
verticalLegend2Style object List of valid settings Set styling of vertical legend text (Performance legend)
verticalGridStyle object List of valid settings Set styling of vertical gridlines
xhr boolean true/false set to true to use XHR instread of script injection, CORS setup needed
xAxisModulo numeric 1 used to lower the amount of legenditems on the x scale
yearLabelsPos string top/bottom (bottom) where to position the new year label, top will rotate the text 90 degrees

Valid fields

field description
symbol instrument symbol
isin instrument isin

Priceindicator details

This setting adds a div to the righthand ylegend which will have the innerHTML set to the last price recieved. The div will have the class "millistream-chart-price-indicator" and can be styled with normal css

Tooltip details

The tooltip setting is an object with a formatter function, the formatter function can access data for the datapoint whith "this".

Available fields in this

field type description
data object Object with data
chartType string Type of chart, can have values "history" or "trades"
name string Instrument name
symbol string Instrument symbol (only available if added to the fields)

Available field in data

field type description
timestamp Unix Epoch timestamp in milliseconds
date date object Date object
diff integer net change in percent since start of chart
insref integer insref of instrument
price integer last price of instrument
x integer x coordinate
y integer y coordinate

Example:

tooltip: {
		formatter: function() {
			var date = formatDate(this.data.date, 'yyyy-mm-dd');
			var time = '';
			if (this.chartType == 'trades') {
				var hour = this.data.date.getHours();
				var minute = '';
				if (this.data.date.getMinutes() < 10) minute = '0';
				minute += this.data.date.getMinutes();
				time = hour + ':' + minute;
			}
			return '<span class="tooltip-name">' + this.name + '</span><br>' + this.data.price + ', '+ this.data.diff.toFixed(2) + '%</br>' + date + ' ' + time;
		}}
}

Styles

chartStyle

property valid values description
backgroundColor valid css color set background color for the canvas
boxShadow object List of properties set top/right bevel
marginBottom integer bottom margin for graph area for x legend ,should be at least 30 (depending on fontsize) to fit the date scale)
marginLeft integer left margin for graph area for y legend
marginRight integer right margin for graph area for y2 legend
marginTop integer top margin for graph area

boxShadow

property valid values description
color css color set color of bevels
rightWidth integer set topbevel width
topWidth integer set topbevel width

Horizontal Legend text styles

property valid values description
color css color Set text color
fontFamily css font-family Set font-family
fontSize integer + 'px' set font size in pixels
fontWeight css font-wegiht set font-weight

Vertical Legend text styles

property valid values description
color css color Set text color
float left/right (left) Draw on right or left side of chart
fontFamily css font-family Set font-family
fontSize integer + 'px' set font size in pixels
fontWeight css font-wegiht set font-weight
textAlign left/right (left) Draw left or right aligned (outside or inside the chart)
verticalAlign top/center (center) Draw above or center of gridline

Vertical Legend2 text styles

This legend inherits all other styling from verticalLegendStyle

property valid values description
float left/right (right) Draw on right or left side of chart

Gridlines styles

property valid values description
color css color vertical gridline colors

Instrument style

property valid values description
color css color chartline color
width integer chartline width
backgroundColor css color fill color underneath line (only available for main instrument)
backgroundLinearGradient object List of properties fill top to bottom gradient color underneath line (only available for main instrument)

backgroundLinearGradient object

property valid values description
topColor css color Top gradient color
bottomColor css color Bottom gradient color

CSS classes

millistream-chart-tooltip

Css for the tooltip "balloon", this is a regular div so all default css classes apply. Must have "position:absolute" to be correctly positioned in the chart

example: .millistream-chart-tooltip { position: absolute; background: #ffffff; border: 1px solid #000000; font-family: Open Sans, Helvetica, sans-serif; font-size: 10px; padding: 2px; pointer-events: none; text-align: center; border-radius: 5px; }

millistream-chart-pointer

Css for the tooltip pointer, this is a regular div so all default css classes apply. Must have "position:absolute" to be correctly positioned in the chart

example: .millistream-chart-pointer { content: ''; margin: 10px; padding: 0px; width: 6px; height: 6px; border-radius: 50%; }

millistream-chart-zoombox

Background shown while zooming.

This is a regular div so all css classes apply.Position is set to absolute and pointer-events is set to none programatically. Background color should be set with opacity so you can still see the chart while zooming, ex: '#f0f0f00a'

Create object

Creates a 1 year chart on insref 6485 (OMS Stockholm 30 index)

new Milli_Chart({
	instrument: 6485,
	token:'your-token-goes-here',
	'target': document.getElementById('chart'),
	historylen: '1y',
	chartlen: '1y'
});

Functions

destroyWidget()

Call to destroy widget.

getDateInverval()

Returns an object with startdate and enddate of the current chart.

drawChart()

Call to redraw chart with new settings or if you have set autodraw to false.

addCompare(insref)

Call to add compare instrument, a maximum of 4 is possible.

refreshData

Call to fetch new data for the chart. Not needed for streaming charts

removeCompare(insref)

Call to remove the compare instrument

removeAllCompares()

Call to remove all compare instruments

setChartLength(chartlen)

Call to change time period to show.

addQuantity()

Call to add quantity bars to the chart. If quantity is already shown, calling this function will remove the quantity bars.

addIndicator({json with indicator information})

Call to add an indicator. List of valid indicators

removeIndicator({json with indicator information})

Call to remove an indicator.List of valid indicators

removeAllIndicators()

Call to remove all indicators.

setDateInverval(startdate,enddate)

Set stardate and enddate for chart, this will set the chart to history

List of valid indicators

Indicator Description Json data
sma Simple Moving Average, x periods {method: 'sma', method_length: x, color: 'rgba color'}
ema Exponenital Moving Average, x periods {method: 'ema', method_length: x, color: 'rgba color'}
bb Bollinger Bands, x periods,y standarddeviation {method: 'bollinger', method_length: x, stddev: y,color: 'rgba color', fill: 'rgba color', border: true/false}

intradayDatePos object

Object to describe how dates should be output on intraday charts

Property Description Valid values default
x horizontal alignment of date text left/center center
y verticacl location in the chart for the date text top/scale/bottom bottom
orientation drawtext orientation horizontal/vertical horizontal
dateformat dateformat see dateformat in settings d mmm

Changelog

2022-09-15	Added absolutScaling setting
			Added analysis setting
			Added closePriceIndicator setting
			Added priceIndicator setting
			Added curveOnTop setting
			Removed intradaydates setting, which did nothing
			Added xAxisModulo setting
			Added indicators setting
			Added removeIndicator function
			Added refreshData function
			Added setDateInverval and getDateInverval functions
			Added intradayDatePos setting
			Added previousDayClose setting