mariusmuntean / ChartJs.Blazor

Brings Chart.js charts to Blazor
https://www.iheartblazor.com/
MIT License
684 stars 152 forks source link

Wrong paths to javascript files #3

Closed larshg closed 5 years ago

larshg commented 5 years ago

Hey

According to the Wiki in point 4, you are supposed to include the following:

But I get an error when running the sample project: Uncaught SyntaxError: Unexpected token < ChartJsInterop.js:1

And I get the above error and one equally about the bootstrap-native.min.js, since I haven't added that to my own project.

I found a CDN for bootstrap-native.minjs //cdnjs.cloudflare.com/ajax/libs/bootstrap.native/2.0.24/bootstrap-native.min.js

and I can use the following path:

_content/ChartJs.Blazor/ChartJsInterop.js

to properly get the ChartJsInterop.js.

The charts does seem to work though, even when the above error(s) are present. When I inspected the errors on my website, they showed 307 internal redirect.

But this doesn't seem to be the case in your example, so maybe that's not really the issue...

What is the intended way to properly refer to the mentioned files?

ghofman2 commented 5 years ago

Also curious about this as I had the same issue. Changing the src path from src="ChartJsInterop.js" to src="_content/ChartJs.Blazor/ChartJsInterop.js" did allow me to be able to locate the file however I get an error on line 3 of ChartJsInterop.js: Uncaught Reference: Blazor is not defined. @larshg did you experience the same issue? If so, did you have a workaround for it? I am using v0.7.0

mariusmuntean commented 5 years ago

@larshg You are correct in referencing ChartJsInterop.js via the path _content/ChartJs.Blazor/ChartJsInterop.js . The Wiki is mistaken and I will fix that.

I don't really know why Blazor is so forgiving when referencing that file the way I did. Unfortunately I can't find any official documentation about referencing Blazor class library content, but here is what I got:

Regarding bootstrap-native.min.js : that file was added by whatever Blazor template I used to create the sample or maybe it is from another project.

It isn't relevant where it comes from, meaning either from static files in wwwroot or from a CDN, as long as it is referenced in index.html I removed it from my sample and in the index.html I used the CDN url that you found and it worked like it did before, so that is the experience I'm basing my claim on.

So to summarize:

@ghofman2 I can't really reproduce your error. When does that message appear? At runtime or is it just your IDE complaining? I think the CharJsInterop.js file needs to be rewritten but from my basic JS understanding the line 3 is correct.

If possible, upload your code to a GitHub repo and share the link. I'll have a look and let you know if I find anything.

McHeff commented 5 years ago

Hey @mariusmuntean did you ever get this working in Blazor 0.7?

PS: Here's a discord server I made for Blazor: https://discord.gg/Xg9ja5s (if you're interested :) )