Skip to content

Commit

Permalink
Reintroduce TimeScale for ChartJS
Browse files Browse the repository at this point in the history
With stock charts we need Time Cartesian Axis for
comparison of securities.

When using time as X scale type we need a way providing
zero labels (an empty array), since these are autogenerated
by TimeScale. In chart-js.service the
method labelsToApply needs a way of returning []
  • Loading branch information
troelslenda committed Mar 2, 2022
1 parent 0c33764 commit e2dccbf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export class ChartJSService {
const typeConfig = this.chartConfigService.getTypeConfig(type);

const labelsToApply = (() => {
if (labels?.length > 0) return labels;
if (Array.isArray(labels)) return labels;
else if (type === 'stock') return this.getDefaultStockLabels(datasets, this.locale);
else return this.createBlankLabels(datasets); // ChartJS requires labels
})();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ import {
LineController,
LineElement,
PointElement,
TimeScale,
Tooltip,
} from 'chart.js';
import 'chartjs-adapter-date-fns';
import annotationPlugin from 'chartjs-plugin-annotation';
import ChartDataLabels from 'chartjs-plugin-datalabels';

import { mergeDeepAll } from '../../../helpers/merge-deep';
import MarkerPlugin from '../chart-js/chartjs-plugin-marker/chartjs-plugin-marker';
import { CHART_GLOBAL_DEFAULTS } from '../configs/global-defaults.config';

const CHART_SCALES = [CategoryScale, LinearScale];
const CHART_SCALES = [CategoryScale, LinearScale, TimeScale];
const CHART_ELEMENTS = [BarElement, LineElement, PointElement];
const CHART_CONTROLLERS = [BarController, LineController];
const CHART_PLUGINS = [annotationPlugin, Filler, ChartDataLabels, Tooltip, MarkerPlugin];
Expand Down

0 comments on commit e2dccbf

Please sign in to comment.