score:1
Accepted answer
Original post:
As you can see at the following example, the same data can be stored to an Object named data
and then create the chart by using chart = anychart.fromJson(data).draw();
Since you want to get this data from a json file, you will have to use something like this: How to get JSON from URL in Javascript?
$.getJSON('http://your_json_url', function(data) {
anychart.fromJson(data).draw();
});
anychart.onDocumentReady(function() {
data = {
chart: {
type: "line",
series: [{
seriesType: "spline",
data: [{
x: "January",
value: 10000
}, {
x: "February",
value: 12000
}, {
x: "March",
value: 18000
}]
}],
container: "container"
}
}
chart = anychart.fromJson(data).draw();
});
<script src="https://cdn.anychart.com/js/7.13.1/anychart-bundle.min.js"></script>
<div id="container"></div>
<link rel="stylesheet" href="https://cdn.anychart.com/css/latest/anychart-ui.min.css">
Edit - working example:
file: test_data.json
(take it as it is)
{
"chart": {
"type": "line",
"series": [{
"seriesType": "spline",
"data": [{
"x": "January",
"value": 10000
}, {
"x": "February",
"value": 12000
}, {
"x": "March",
"value": 18000
}]
}],
"container": "container"
}
}
file: index.html
(modify the url of the json file)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.anychart.com/js/7.13.1/anychart-bundle.min.js"></script>
<link rel="stylesheet" href="https://cdn.anychart.com/css/latest/anychart-ui.min.css">
</head>
<body>
<div id="container"></div>
</body>
</html>
<script>
$(document).ready(function(){
$.getJSON('http://localhost/json_chart_test/test_data.json', function(data) {
console.log(data);
anychart.fromJson(data).draw();
});
});
</script>
Source: stackoverflow.com
Related Query
- Will chart that reads embedded JSON also read JSON file?
- How to have an interactive D3 chart read a json file instead of csv data?
- How can I put a json object into a test file ("file.json") and then read that file in a d3.json("file.json", function(error, root))?
- D3.js : How to read data from JSON in Grouped Bar Chart
- Does anyone know of a Javascript .csv file reader that will create an associative array?
- Using External json file for creating bubble chart using d3js
- Javascript d3 pie chart doesn't pull data from JSON file with list of dictionaries
- How to change json file in d3.js and update chart using select options
- Uncaught TypeError: Cannot read property 'length' of undefined in line chart with json data
- "Cannot read property 'length' of null" with Angular-cli and a json file
- I have a php file which gives JSON output and want to use that JSON in D3
- D3js multiple line chart from json file
- d3.json cant read from json file more than one object
- How to read specific attribute from external json file using d3.js?
- Populating D3 chart with external JSON file
- Creating a d3 horizontal bar chart with a multidimensional array/nested json file
- Converting separate data frames to a JSON file for a tidy tree chart
- modifying d3.js donut chart to read from json array
- Read Data from JSON file using d3.js
- how to draw a d3 pie chart from a json file
- How to use coffeescript or javascript to read value of json file / parse to be use in d3 java script
- D3.js horizontal bar chart and data from json file
- How do you create a survey that will immediately display the results as a pie chart on a website?
- D3 + Angular 4 + chrome not able to read JSON file from local IP
- how to read json file in d3 using pie chart?
- d3 Responsive grouped bar chart with tooltip using json file
- Take input for treemap using json objects not to read from csv file
- Use json file instead of csv in d3.js pie chart
- how to read path info from json file using d3
- Getting data from json file for D3 bubble chart
More Query from same tag
- How to understand selection.data()
- Update selection not working
- How to pass values between drag.start and drag.end in d3
- D3 Force Layout : How to force a group of node to stay in a given area
- Best Way to Visualize Large Number of Categories
- How can I rotate d3 chart and how can I start pie chart from angle -90?
- Colons in field names messes up d3 code
- Line-Bar Chart: how to set the xAxis ticks when I have 2 series of 2 different frequencies?
- placing d3 label at end of arc
- d3js scatterplot custom icons and animation
- How can I use D3.CSV to get values
- Recreate D3 Multi-Line Chart on Resize (responsive)
- Alternating axis line colors in D3
- How to generate SVG using dimple in Node.js
- d3.js loop number as variable for
- Three.js Points Rotation
- Differing values for d3.scale.pow(0.5) versus d3.scale.sqrt()
- Alter edge length and cluster spacing in networkx/matplotlib force graph
- D3: How can I change data in an existing bar chart
- d3 zoom behavior when window is resized
- override extent for one horizon instance
- D3 remove parents of elements returned by exit
- Is there a way to make the nodes draggable/to another parent or child node to rearrange the nodes in d3.js
- d3.js - Zoom and Center on Click - Map scales, points do not
- unable to add scrollbar to svg
- TypeError: Cannot call method 'forEach' of undefined " in d3 js on MVC Razor
- How to convert/export d3.js graph (callapsible tree) to SVG/PDF/PNG
- add custom elements based on css styles not images to chart D3.js
- csv filsize limit when importing with d3.csv
- d3.js arrow directed graph: adding nodes/links on the fly