12

I want to use Chartjs(chartjs.org) as my charting tool along with AngularJS using TypeScript. I have installed DefinitelyTyped for Chartjs from GitHub to incorporate creation of Chartjs charts in my TypeScript written controller. I can't find any related questions on doing this thing.

I just need to know how we populate data to our charts using DefinitelyTyped.

2 Answers 2

11

You can find example usages of chart.d.ts in the form of a tests file right next to the definition in the DefinitelyTyped repo.

Sign up to request clarification or add additional context in comments.

1 Comment

indeed, types are part of chat.js now, no need to install @types/chart.js
5

A bit outdated question, but had similar request since I'm working with Angular + PrimeNG (which uses chart.js) with npm for packages.

Just install types from

npm i --save-dev @types/chart.js

and then use it for example:

import { Chart } from 'chart.js';

…

const myOptions: Chart.ChartOptions = {
  title: {
    display: true,
    text: 'My title',
    fontSize: 16,
  },
};

Might help someone.

4 Comments

This is wrong, you are using Chart.js V3, in V3 the types are build in while @types/chart.js has the types for V2 which will collide
Well, not sure about types compatibility (of course you should not use types for ver. 2.x with 3.x chart.js..) but this is working fine with version 2.9.4 which I'm using, also there is no specified version in question.
How this works with V4? I added /// <reference path="node_modules/chart.js/dist/types/index.d.ts" /> but no intellisense.
@Saftpresse99 try adding "compilerOptions": { "types": ["chart.js"] } to your tsconfig

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.