1

i am beginner in angular and chartjs. I want to load same data file in different chart. so i create a json file. and i want to load it my chart.

My code is like below

external_data.json

[{
    "data": "[13, 22, 30, 40, 50]",
    "label": "Africa",
    "borderColor": "#3e95cd",
    "fill": "false"
}, {
    "data": "[47, 14, 37, 67, 80]",
    "label": "Asia",
    "borderColor": "#8e5ea2",
    "fill": "false"
}]

line-chart.component.ts

       var ctx = document.getElementById("line-chart");

    new Chart(ctx, {


        type: 'line',
        data: {
            labels: [1850, 1900, 1950, 2000, 2050],

           datasets:  // i want get json here

        }

    });

this is folder structure

1 Answer 1

1

Juse mention the path as follows,

loaddata() {
   this.Items = this.http.get("../data/external_data.json")
                 .map(res => res.json());
 }

and assign this.Items to your array

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

4 Comments

get some error like that [ts] Property 'map' does not exist on type 'Observable<Response>'
you need to import import 'rxjs/add/operator/map'
its ok.. but now get this ERROR TypeError: Cannot read property 'get' of undefined
import http inside your constructor

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.