Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.8.0 docs say to use Chart.helpers.... but ['helpers'] does not exist #10397

Closed
orbitr-dudewad opened this issue Jun 4, 2022 · 2 comments · Fixed by #10434
Closed

3.8.0 docs say to use Chart.helpers.... but ['helpers'] does not exist #10397

orbitr-dudewad opened this issue Jun 4, 2022 · 2 comments · Fixed by #10434

Comments

@orbitr-dudewad
Copy link

Expected behavior

Per the docs here you can use the Chart class's helpers member to perform helper function type things.

However, Chart.helpers doesn't exist when I run an npm install.

When I use the codepen link, Chart.helpers does exist. I'm not sure what the discrepancy is between

https://npmcdn.com/chart.js@latest/dist/chart.min.js and the npm version chart.js@latest but something is off.
Package.json has it listed at 3.8.0.

I copied/pasted the example code and it still wont work.

For what its worth, I am using this with ng2-charts, however a direct class import should still show the full implementation.
Curious if I'm doing something wrong.

Current behavior

Chart.helpers doesn't exist.

Reproducible sample

https://codepen.io/pen?template=BapRepQ

Optional extra steps/info to reproduce

Full source from the node_modules v3.8.0 package for the Chart class after pulling it locally:

export declare class Chart<
  TType extends ChartType = ChartType,
  TData = DefaultDataPoint<TType>,
  TLabel = unknown
> {
  readonly platform: BasePlatform;
  readonly id: string;
  readonly canvas: HTMLCanvasElement;
  readonly ctx: CanvasRenderingContext2D;
  readonly config: ChartConfiguration<TType, TData, TLabel>;
  readonly width: number;
  readonly height: number;
  readonly aspectRatio: number;
  readonly boxes: LayoutItem[];
  readonly currentDevicePixelRatio: number;
  readonly chartArea: ChartArea;
  readonly scales: { [key: string]: Scale };
  readonly attached: boolean;

  readonly legend?: LegendElement<TType>; // Only available if legend plugin is registered and enabled
  readonly tooltip?: TooltipModel<TType>; // Only available if tooltip plugin is registered and enabled

  data: ChartData<TType, TData, TLabel>;
  options: ChartOptions<TType>;

  constructor(item: ChartItem, config: ChartConfiguration<TType, TData, TLabel>);

  clear(): this;
  stop(): this;

  resize(width?: number, height?: number): void;
  ensureScalesHaveIDs(): void;
  buildOrUpdateScales(): void;
  buildOrUpdateControllers(): void;
  reset(): void;
  update(mode?: UpdateMode): void;
  render(): void;
  draw(): void;

  isPointInArea(point: Point): boolean;
  getElementsAtEventForMode(e: Event, mode: string, options: InteractionOptions, useFinalPosition: boolean): InteractionItem[];

  getSortedVisibleDatasetMetas(): ChartMeta[];
  getDatasetMeta(datasetIndex: number): ChartMeta;
  getVisibleDatasetCount(): number;
  isDatasetVisible(datasetIndex: number): boolean;
  setDatasetVisibility(datasetIndex: number, visible: boolean): void;
  toggleDataVisibility(index: number): void;
  getDataVisibility(index: number): boolean;
  hide(datasetIndex: number, dataIndex?: number): void;
  show(datasetIndex: number, dataIndex?: number): void;

  getActiveElements(): ActiveElement[];
  setActiveElements(active: ActiveDataPoint[]): void;

  destroy(): void;
  toBase64Image(type?: string, quality?: unknown): string;
  bindEvents(): void;
  unbindEvents(): void;
  updateHoverStyle(items: InteractionItem[], mode: 'dataset', enabled: boolean): void;

  notifyPlugins(hook: string, args?: AnyObject): boolean | void;

  static readonly defaults: Defaults;
  static readonly overrides: Overrides;
  static readonly version: string;
  static readonly instances: { [key: string]: Chart };
  static readonly registry: Registry;
  static getChart(key: string | CanvasRenderingContext2D | HTMLCanvasElement): Chart | undefined;
  static register(...items: ChartComponentLike[]): void;
  static unregister(...items: ChartComponentLike[]): void;
}

As you can see there is no helpers member on this class.

Possible solution

No response

Context

No response

chart.js version

3.8.0

Browser name and version

N/A (issue occurs in code)

Link to your project

No response

@LeeLenaleee
Copy link
Collaborator

https://www.chartjs.org/docs/master/getting-started/integration.html#helper-functions

@orbitr-dudewad
Copy link
Author

@LeeLenaleee This will likely fix my issue -- however the docs are, then, out of sync. As referenced there is documentation that says to use Chart.helpers... - this seems like a documentation issue. Thanks for the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants