5

I have to create a Dashboard for my customer using VueJS + Typescript and D3.js.

They are using dotnet vue template: 'dotnet new –install Microsoft.AspNetCore.SpaTemplates::*' 'dotnet new vue'

Everything is setup on installation: Webpack, Typescript and VueJS

This Webpack setup does not accept <script lang="ts"></script> and most of the tutorials uses it to import D3.js library.

Is there any way to reconfigure webpack in this template to accept <script lang="ts"></script>?

Error after I install d3 and d3 typings

Best

1
  • Is there a reason you can't download D3 (for example, via npm install d3) and import it inside your Typescript code? Commented Oct 14, 2017 at 1:19

1 Answer 1

9

I don't know why would you like to use <script> instead of the typical npm based approach. There are many examples/tutorial in the Internet on that topic. Normally, what you do is a few steps:

  1. Install d3 as npm dependency: npm install --save d3
  2. Since you're writing code in TypeScript, it's helpful to get some type support: npm install --save-dev @types/d3
  3. In your typescript file import the types by adding the next line at the very top of it: import * as d3 from "d3";
  4. Use it. d3.select(...)
Sign up to request clarification or add additional context in comments.

4 Comments

I think the you mean npm install --save d3 instead of npm install --save-dev d3?
And probably the types are --save-dev :)
Thank you for your answer. I have installed d3.js and d3.js typings for typescript. However, when I type in d3.select("#chart").append("svg:svg"); everything being underlined in red and compiler gives a lot of errors. I have added image to my original post.
@Ksistof you can't write it directly in your class. if you wrap it with a function the errors will disappear

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.