Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
c3-closed
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
charts
c3-closed
Commits
ba997024
Commit
ba997024
authored
Jun 21, 2014
by
Masayuki Tanaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix load API with JSON - #379
parent
fed1ec4a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
21 deletions
+37
-21
c3.js
c3.js
+14
-15
c3.min.js
c3.min.js
+0
-0
c3_test_2.json
htdocs/data/c3_test_2.json
+5
-0
data_url.html
htdocs/samples/data_url.html
+18
-6
No files found.
c3.js
View file @
ba997024
...
...
@@ -1494,6 +1494,18 @@
}
return
x
;
}
function
convertUrlToData
(
url
,
mimeType
,
keys
,
done
)
{
var
type
=
mimeType
?
mimeType
:
'csv'
;
d3
.
xhr
(
url
,
function
(
error
,
data
)
{
var
d
;
if
(
type
===
'json'
)
{
d
=
convertJsonToData
(
JSON
.
parse
(
data
.
response
),
keys
);
}
else
{
d
=
convertCsvToData
(
data
.
response
);
}
done
(
d
);
});
}
function
convertCsvToData
(
csv
)
{
var
rows
=
d3
.
csv
.
parseRows
(
csv
),
d
;
if
(
rows
.
length
===
1
)
{
...
...
@@ -4457,7 +4469,7 @@
load
(
convertDataToTargets
(
args
.
data
),
args
);
}
else
if
(
args
.
url
)
{
d3
.
csv
(
args
.
url
,
function
(
error
,
data
)
{
convertUrlToData
(
args
.
url
,
args
.
mimeType
,
args
.
keys
,
function
(
data
)
{
load
(
convertDataToTargets
(
data
),
args
);
});
}
...
...
@@ -5296,21 +5308,8 @@
/*-- Load data and init chart with defined functions --*/
function
initWithUrl
(
args
)
{
var
type
=
args
.
mimeType
?
args
.
mimeType
:
'csv'
;
d3
.
xhr
(
args
.
url
,
function
(
error
,
data
)
{
var
d
;
if
(
type
===
'json'
)
{
d
=
convertJsonToData
(
JSON
.
parse
(
data
.
response
),
args
.
keys
);
}
else
{
d
=
convertCsvToData
(
data
.
response
);
}
init
(
d
);
});
}
if
(
config
.
data
.
url
)
{
initWithUrl
(
config
.
data
);
convertUrlToData
(
config
.
data
.
url
,
config
.
data
.
mimeType
,
config
.
data
.
keys
,
init
);
}
else
if
(
config
.
data
.
json
)
{
init
(
convertJsonToData
(
config
.
data
.
json
,
config
.
data
.
keys
));
...
...
c3.min.js
View file @
ba997024
This source diff could not be displayed because it is too large. You can
view the blob
instead.
htdocs/data/c3_test_2.json
0 → 100644
View file @
ba997024
{
"data1"
:
[
20
,
40
,
70
,
50
,
80
,
30
],
"data2"
:
[
180
,
150
,
200
,
170
,
220
,
400
],
"data3"
:
[
1200
,
1210
,
1250
,
1300
,
1280
,
1000
]
}
htdocs/samples/data_url.html
View file @
ba997024
...
...
@@ -3,27 +3,39 @@
<link
href=
"/css/c3.css"
rel=
"stylesheet"
type=
"text/css"
>
</head>
<body>
<div
id=
"chart1"
></div>
<div
id=
"chart2"
></div>
<div
id=
"chart"
></div>
<script
src=
"http://d3js.org/d3.v3.min.js"
charset=
"utf-8"
></script>
<script
src=
"/js/c3.js"
></script>
<script>
var
chart1
=
c3
.
generate
({
bindto
:
'#chart1'
,
var
chart
=
c3
.
generate
({
data
:
{
url
:
'/data/c3_test.csv'
}
});
var
chart2
=
c3
.
generate
({
bindto
:
'#chart2'
,
setTimeout
(
function
()
{
chart
.
load
({
url
:
'/data/c3_test2.csv'
,
});
},
1000
);
setTimeout
(
function
()
{
chart
=
c3
.
generate
({
data
:
{
url
:
'/data/c3_test.json'
,
mimeType
:
'json'
}
});
},
2000
);
setTimeout
(
function
()
{
chart
.
load
({
url
:
'/data/c3_test_2.json'
,
mimeType
:
'json'
});
},
3000
);
</script>
</body>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment