What is highcharts?
The highcharts npm package is a charting library that allows developers to create interactive and responsive charts for web applications. It supports a wide range of chart types and features, including line, area, bar, pie, scatter, and more complex types like stock, maps, and Gantt charts. Highcharts is designed to work across all modern browsers and is compatible with various frameworks and platforms.
What are highcharts's main functionalities?
Line Charts
This code sample demonstrates how to create a basic line chart using Highcharts, showing the growth of solar employment in various sectors over time.
{"title": {"text": 'Solar Employment Growth by Sector, 2010-2016'},"subtitle": {"text": 'Source: thesolarfoundation.com'},"yAxis": {"title": {"text": 'Number of Employees'}},"legend": {"layout": 'vertical',"align": 'right',"verticalAlign": 'middle'},"plotOptions": {"series": {"label": {"connectorAllowed": false},"pointStart": 2010}},"series": [{"name": 'Installation',"data": [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]},{"name": 'Manufacturing',"data": [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434]},{"name": 'Sales & Distribution',"data": [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387]},{"name": 'Project Development',"data": [null, null, 7988, 12169, 15112, 22452, 34400, 34227]},{"name": 'Other',"data": [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111]}],"responsive": {"rules": [{"condition": {"maxWidth": 500},"chartOptions": {"legend": {"layout": 'horizontal',"align": 'center',"verticalAlign": 'bottom'}}}]}}
Pie Charts
This code sample shows how to create an interactive pie chart with Highcharts, displaying browser market shares with options for selecting and slicing portions of the pie.
{"chart": {"plotBackgroundColor": null,"plotBorderWidth": null,"plotShadow": false,"type": 'pie'},"title": {"text": 'Browser market shares in January, 2018'},"tooltip": {"pointFormat": '{series.name}: <b>{point.percentage:.1f}%</b>'},"accessibility": {"point": {"valueSuffix": '%'}},"plotOptions": {"pie": {"allowPointSelect": true,"cursor": 'pointer',"dataLabels": {"enabled": true,"format": '<b>{point.name}</b>: {point.percentage:.1f} %'}}},"series": [{"name": 'Brands',"colorByPoint": true,"data": [{"name": 'Chrome',"y": 61.41,"sliced": true,"selected": true},{"name": 'Internet Explorer',"y": 11.84},{"name": 'Firefox',"y": 10.85},{"name": 'Edge',"y": 4.67},{"name": 'Safari',"y": 4.18},{"name": 'Other',"y": 7.05}]}]}
3D Charts
This code sample illustrates how to create a 3D column chart using Highcharts, which adds a new dimension to the data visualization for better analysis and presentation.
{"chart": {"type": 'column',"options3d": {"enabled": true,"alpha": 15,"beta": 15,"viewDistance": 25,"depth": 40}},"title": {"text": 'Total fruit consumption, grouped by gender'},"plotOptions": {"column": {"depth": 25}},"series": [{"name": 'John',"data": [2, 3, 0, 4, 5]},{"name": 'Joe',"data": [1, 1, 4, 7, 2]}]}
Other packages similar to highcharts
chart.js
Chart.js is a popular open-source charting library that is lightweight and offers a simple API. It supports eight chart types, including line, bar, radar, doughnut, pie, polar area, bubble, and scatter. Compared to Highcharts, Chart.js is more focused on simplicity and ease of use, but it may not offer as many features or as much flexibility for complex visualizations.
d3
D3.js is a powerful and flexible library for creating custom data visualizations using web standards. It provides a low-level approach, giving developers more control over the final visualization. While Highcharts offers a high-level API for creating standard chart types easily, D3.js requires more coding but allows for more unique and intricate visualizations.
echarts
ECharts is an open-source charting library that offers a rich set of chart types and options. It is capable of producing interactive and complex charts and maps. ECharts is similar to Highcharts in terms of functionality but is known for its strong support for mobile devices and ease of integration with the Baidu Map service.
amcharts
amCharts is a comprehensive charting library that provides a wide array of chart types and features, including 3D charts, gauge charts, and timelines. It is comparable to Highcharts in terms of its feature set and is known for its user-friendly interface and extensive documentation. However, amCharts uses a different licensing model, which may be a consideration for some projects.
Highcharts
Highcharts for node.js is a WebServer module that runs on localhost and renders typical Highcharts graphs into base64 PNG strings.
All contributions are welcome.
Simple API
Class: Highcharts
Highcharts has the following methods.
new Highcharts(port)
port
Number. Port to bind webserver to localhost.
Constructor for creating a Highcharts web server instance.
render(imgOptions, chartOptions, callback)
imgOptions
Object. Rendered image options.chartOptions
Object. General Highcharts options.callback
Function. The callback has argument (base64png)
, a base64 PNG data string.
Example Usage
var Highcharts = require('highcharts');
var server = new Highcharts(3003);
var chartOptions = {
title: {
text: 'Monthly Average Temperature',
x: -20
},
subtitle: {
text: 'Source: WorldClimate.com',
x: -20
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: {
title: {
text: 'Temperature (C)'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
valueSuffix: 'C'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
series: [
{
name: 'Tokyo',
data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
},
{
name: 'New York',
data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
},
{
name: 'Berlin',
data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]
},
{
name: 'London',
data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
}
]
};
var imgOptions = {
width: 640,
scale: 2
};
function generateImgTag(base64png) {
return '<img src="data:image/png;base64,' + base64png + '" alt="Monthly Average Temperature" />';
}
server.render(imgOptions, chartOptions, generateImgTag);
Installation
npm install highcharts
License
(The MIT License)
Copyright (c) frisB.com <play@frisb.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.