2.0.5 ā€¢ Published 3 years ago

pixie-highcharts v2.0.5

Weekly downloads
9
License
MIT
Repository
github
Last release
3 years ago

Build Status npm version Downloads FOSSA Status Donate

Pixie Highcharts

pixie-highcharts is a wrapper of the highcharts and apply two-way data-binding of the option like series, tooltip, color, xAxis, yAxis, navigator, range selector, and etc. pixie-highcharts is breaking down the option into data, type, xAxis, colors, navigator, tooltips as Input and events as EventEmitter. Its use to avoid any additional logic and make your life easy just input and visualize. pixie-highcharts support for dynamic manipulations, event action and provides developer access to the original chart object.

Table of Contents

Installation

NPM

npm install pixie-highcharts highcharts --save

Yarn

yarn add pixie-highcharts highcharts

Environment

Minimum Software Version Requirement

  • node v6.16.0+
  • npm 4.6.1+
  • @angular/cli 1.7.6+

Getting started

Setup App @NgModule

Import PixieHighchartsModule into your @NgModule in app.module.ts

// File: app.module.ts
import { PixieHighchartsModule } from 'pixie-highcharts';

@NgModule({
  imports: [PixieHighchartsModule.forRoot(require('highcharts'))]
})
export class AppModule {}

Let Start With Basis Hello World's Highcharts Visualization

šŸ“ˆ Hello World Demo

HTML

<pixie-highcharts
  [type]="type"
  [zoomType]="zoomType"
  [data]="data"
  [xAxis]="xAxis"
  [yAxis]="yAxis"
  [footer]="footer"
  [colors]="color"
  [tooltip]="tooltip"
  [export]="exporting"
  [config]="config"
  [isStacked]="true"
>
</pixie-highcharts>

TypeScript

export class AppComponent {
  type = 'bar';
  zoomType = 'x';
  data = [
    {
      name: 'OMAK-C',
      data: [
        { x: 1512691300000, y: 2.787037037037037, equipmentName: 'OMAK-C' },
        { x: 1512691400000, y: 61.638888888888886, equipmentName: 'OMAK-C' },
        { x: 1512691500000, y: 56.97222222222222, equipmentName: 'OMAK-C' },
        { x: 1512692200000, y: 67.7962962962963, equipmentName: 'OMAK-C' },
        { x: 1512693200000, y: 58.2037037037037, equipmentName: 'OMAK-C' }
      ]
    }
  ];
  xAxis = { title: { text: 'Sample X-Axis' }, type: 'category' };
  yAxis = { title: { text: 'Sample Y-Axis' } };
  footer = 'Sample Footer';
  color = ['rgb(0, 255, 255)', 'rgb(246, 107, 0)', 'rgb(115, 211, 44)', 'rgb(227, 2, 42)', 'rgb(23,119,25)'];
  tooltip = {
    headerFormat: '<span style="font-size:10px">{point.key}</span><table style="margin-bottom:unset">',
    pointFormat:
      '<tr><td style="color:{series.color};padding:0">{series.name}</td>' +
      '<td style="padding:0"> : </td>' +
      '<td style="padding:0"><b>{point.y}</b></td></tr>',
    footerFormat: '</table>',
    xDateFormat: '%A, %b %d, %Y',
    shared: true,
    useHTML: true
  };
  exporting = { title: 'Volume', filename: 'Volume', scale: 3 };
  config = { legend: { borderWidth: 0, borderRadius: 0, itemMarginTop: 0, padding: 0 } };
}

šŸ“Š Live Demo

Options

InputClassDefault ValueReference
idString5 Digit of ID will generated if no Input
typeStringchart.type
zoomTypeStringchart.zoomType
titleObject
xAxisObjectxAxis
yAxisObjectyAxis
zAxisObjectzAxis
tooltipObjecttooltip
exportExport
colorsArray<String>
colorAxisObjectcolorAxis
footerString
dataArray<any>series
configObjectAdditional Highcharts Option/Object not exist in Pixie Highcharts
isLegendBooleanTrueT-Enable Legend, F-Disable Legend
isUTCBooleanFalseT-UTC+Based on Browser UTC, F-UTC+0
isPolarBooleanFalseT-Polar Shape like Radar
isBoostBooleanFalseT-Boost the Chart
isBoostDebugBooleanFalseT-Debug of the boost mode boost.debug
isTooltipMovedBooleanTrueT-Tooltip Will Move Based on the Cursor
isAnimationBooleanTrueT-Animation will Animate (Load & Update)
isGapBooleanTrueT-Gap Size Between Each Point : Display a Gap in the Graph
gapSizeNumber86400000 @ 1 DayDay-To-Day Disconnected
gapUnitStringvalue
isPointRangeBooleanFalseT-Each Point Wont Have the Hours Based on pointRange Set
pointRangeNumber86400000 @ 1 DayDay-To-Day Connected
isAxisPrefixBooleanFalseT-Active Conversation Metric Prefix Table
axisPrefixFloatNumber2
isStockBooleanFalseT-Enable Stock Chart Highstock is required
isMapBooleanFalseT-Enable Map Chart Highmaps or map module is required
isStackedBooleanFalseT-Enable Stack Chart for Bar, Column, Line, etc
isGroupBooleanFalseT-Enable Group Chart for Bar, Column, Line, etc
rangeSelectorObjectrangeSelector
isRangeSelectorBooleanTrueT-Enable Range Selector, F-Disable Range Selector
isRangeInputBooleanFalseT-Enable Range Input, F-Disable Range Input
navigatorObjectnavigator
navigatorDataObjectnavigator.series
isXScrollbarBooleanFalseT-Enable xAxis Scrollbar, F-Disable xAxis Scrollbar
isYScrollbarBooleanFalseT-Enable yAxis Scrollbar, F-Disable yAxis Scrollbar
referenceUpdateBooleanFalseT-Enable Options Update, F-New Options Object Created when Update

Events

Highcharts provides bunch of events, and you can use option method to handle those events, but it is not common angular way to handle events. So that pixie-highcharts provides EventEmitter<ChartEvent> wrappers for highcharts events. ChartEvent is an class which simply wraps original Highcharts events (chartEvent.originalEvent) and adds event handler context (chartEvent.context) since it differs depending on events. Concept of Handling events is learning from angular2-highcharts and enhancement made in pixie-highcharts. Thanks for angular2-highcharts founder.

Chart Events

All the events from the chart.events are available as output properties of the chart component.

<pixie-highcharts (selection)="onChartSelection($event)"></pixie-highcharts>

<p>Selection area from <b>{{from}}</b> to <b>{{to}}</b></p>
onChartSelection (e) {
  this.from = e.originalEvent.xAxis[0].min.toFixed(2);
  this.to = e.originalEvent.xAxis[0].max.toFixed(2);
}

šŸ“Š Live Demo

Series Events

To use series events the same way you need to add the series component as a child of your pixie-highcharts. The only purpose of this auxiliary component is to provide access to plotOptions.series.events API

<pixie-highcharts>
  <series (legendItemClick)="onLegendClick($event)"></series>
</pixie-highcharts>
<p><b>{{serieName}}</b> is clicked</p>
onLegendClick (e) {
  this.serieName = e.context.name;
}

šŸ“Š Live Demo

Point Events

Similary you can use the point to access to plotOptions.series.point.events API.

<pixie-highcharts>
  <series>
    <point (click)="onPointClick($event)"></point>
  </series>
</pixie-highcharts>
<p><b>{{point}}</b> is clicked</p>

šŸ“Š Live Demo

Axis Events

Similary you can use the xAxis or yAxis or zAxis to access to xAxis.events or yAxis.events or zAxis.events API.

<pixie-highcharts>
  <xAxis (afterSetExtremes)="onAfterSetExtremesX($event)"></xAxis>
  <yAxis (afterSetExtremes)="onAfterSetExtremesY($event)"></yAxis>
  <zAxis (afterSetExtremes)="onAfterSetExtremesZ($event)"></zAxis>
</pixie-highcharts>
<p>ExtremesX: <b>{{minX}}</b> - <b>{{maxX}}</b></p>
<p>ExtremesY: <b>{{minY}}</b> - <b>{{maxY}}</b></p>
<p>ExtremesZ: <b>{{minZ}}</b> - <b>{{maxZ}}</b></p>
onAfterSetExtremesX (e) {
  this.minX = e.context.min;
  this.maxX = e.context.max;
}

onAfterSetExtremesY (e) {
  this.minY = e.context.min;
  this.maxY = e.context.max;
}

onAfterSetExtremesZ (e) {
  this.minZ = e.context.min;
  this.maxZ = e.context.max;
}

šŸ“Š Live Demo

ColorAxis Events

Similary you can use the colorAxis to access to colorAxis.events API.

<pixie-highcharts>
  <colorAxis (legendItemClick)="onLegendClick($event)"></colorAxis>
</pixie-highcharts>
<p><b>{{colorLegend}}</b> is clicked</p>

šŸ“Š Live Demo

Navigation Events

Similary you can use the navigation to access to navigation.events API.

Members

Chart instance. You can call load methods to get the instance. Highcharts.Chart

<pixie-highcharts (load)="onLoad($event)"> </pixie-highcharts>
onLoad (e) {
  this.chartInstance = e;
}

šŸ“Š Live Demo

Localization

Currently, highcharts doesn't provide localization for the language you wish to display. Right now, pixie-highcharts supporting localization.

import { LocaleService } from 'pixie-highcharts';

export class Component implements OnInit {
  constructor(private localeService: LocaleService) {
    this.localeService.setLocale('zh');
  }
}

Current word support for localization is resetZoom, noDataAvailable, months[], shortMonths[], weekdays[] in Localization File

Global Variable and Class for Pixie Highcharts

For normal way to generate highcharts visualization, you required to declare style, tooltips, exporting, datetime format, and url again and again for the options. For pixie-highcharts you no need to declare repeatedly.

import * as hc from 'highcharts';
// OR
const hc = require('highcharts');
const globalPXH: GlobalPXH = {};
const exportPXH: Export = {};

// Declare Global Variable for Each COnfig
exportPXH.theme = {
  chart: {
    backgroundColor: '#23232A',
    spacingTop: 10,
    style: { fontFamily: 'Arial', color: '##FFF' }
  }
};
exportPXH.filename = 'Pixie Highcharts';
globalPXH.export = exportPXH;

globalPXH.url = 'https://github.com/briankpw/pixie-highcharts';
globalPXH.debug = true;

// Assign globalPXH to Highcharts
hc.globalPXH = globalPXH;

GlobalPXH

InputClassDefault ValueReference
standardTooltipDesignObjectBelow defaultTooltip
dateTimeLabelFormatsObjectBelow defaultDateTimexAxis.dateTimeLabelFormats
sameLegendSymbolBooleanFalseT-All legend will fixed column legend symbol
legendPositionStringtoplegend.verticalAlign
urlStringFooter URL
exportExportExport
debugBooleanFalseT-Turn on Debug (View compile options, error, and etc)
debugStringifyBooleanFalseT-Turn on Debug with stringify output
const defaultTooltip = {
  headerFormat: '<span style="font-size:10px">{point.key}</span><table style="margin-bottom:unset">',
  pointFormat:
    '<tr><td style="color:{series.color};padding:0">{series.name}</td>' +
    '<td style="padding:0"> : </td>' +
    '<td style="padding:0"><b>{point.y}</b></td></tr>',
  footerFormat: '</table>',
  useHTML: true
};

const defaultDateTime = {
  millisecond: '%H:%M:%S.%L',
  second: '%H:%M:%S',
  minute: '%H:%M',
  hour: '%H:%M',
  day: '%b %e',
  week: '%b %e',
  month: '%b, %y',
  year: '%y'
};

Export

InputClassDefault ValueReference
titleStringExport title if null, default chart title will be consider
subtitleStringExport subtitle if null, default chart title will be consider
filenameString
widthNumber600exporting.sourceWidth
heightNumber800exporting.sourceHeight
scaleNumberAutomated adjust export resolution for image and pdf
urlStringexporting.url
themeObjectexporting.chartOptions
enabledBooleanTrueT-Turn on exporting button
fallbackToExportServerBooleanTrueT-Fallback to export server if offline exporting failure
customExportBooleanFalseFlag for custom Highcharts event, function, any (Custom Script)
clearDefaultFieldBooleanFalseFlag for clear default series rows/columns data (Custom Script)

Title

InputClass
titleString
subtitleString

Highstock

<pixie-highcharts [isStock]="true"></pixie-highcharts>

Don't forget, You need to update @NgModule in app.module.ts

// File: app.module.ts
...
@NgModule({
  imports: [
    PixieHighchartsModule.forRoot(
    require('highcharts'),
    require('highcharts/modules/stock'))
  ]
})
...

šŸ“Š Live Demo

Highmaps

<pixie-highcharts [isMap]="true"></pixie-highcharts>

Don't forget, You need to update @NgModule in app.module.ts

// File: app.module.ts
...
@NgModule({
  imports: [
    PixieHighchartsModule.forRoot(
    require('highcharts'),
    require('highcharts/modules/map'))
  ]
})
...

Highcharts Static API

import { PixieHighchartsModule, HighchartsStatic } from 'pixie-highcharts';

...
export function highchartsFactory() {
  const hc = require('highcharts');
  const hs = require('highcharts/modules/stock');
  const exp = require('highcharts/modules/exporting');
  const expd = require('highcharts/modules/export-data');

  hs(hc);
  exp(hc);
  expd(hc);

  return hc;
}

...
@NgModule({
  imports: [PixieHighchartsModule],
  providers: [
    {
      provide: HighchartsStatic,
      useFactory: highchartsFactory
    }
  ]
})
...

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT @ Brian Koh Ping Weng

FOSSA Status

2.0.5

3 years ago

2.0.4

3 years ago

2.0.3

3 years ago

2.0.2

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago