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
c8b42c2f
Commit
c8b42c2f
authored
May 29, 2014
by
Masayuki Tanaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add data.keys for filter input data - #283
parent
0c4a3ba6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
16 deletions
+60
-16
c3.js
c3.js
+32
-14
c3.min.js
c3.min.js
+0
-0
data_json.html
htdocs/samples/data_json.html
+28
-2
No files found.
c3.js
View file @
c8b42c2f
...
@@ -327,7 +327,7 @@
...
@@ -327,7 +327,7 @@
var
isTimeSeries
=
(
__axis_x_type
===
'timeseries'
),
var
isTimeSeries
=
(
__axis_x_type
===
'timeseries'
),
isCategorized
=
(
__axis_x_type
===
'categorized'
),
isCategorized
=
(
__axis_x_type
===
'categorized'
),
isCustomX
=
!
isTimeSeries
&&
(
__data_x
||
notEmpty
(
__data_xs
))
;
isCustomX
=
function
()
{
return
!
isTimeSeries
&&
(
__data_x
||
notEmpty
(
__data_xs
));
}
;
var
dragStart
=
null
,
dragging
=
false
,
cancelClick
=
false
,
mouseover
=
false
,
transiting
=
false
;
var
dragStart
=
null
,
dragging
=
false
,
cancelClick
=
false
,
mouseover
=
false
,
transiting
=
false
;
...
@@ -1449,7 +1449,7 @@
...
@@ -1449,7 +1449,7 @@
if
(
isTimeSeries
)
{
if
(
isTimeSeries
)
{
x
=
rawX
?
rawX
instanceof
Date
?
rawX
:
parseDate
(
rawX
)
:
parseDate
(
getXValue
(
id
,
index
));
x
=
rawX
?
rawX
instanceof
Date
?
rawX
:
parseDate
(
rawX
)
:
parseDate
(
getXValue
(
id
,
index
));
}
}
else
if
(
isCustomX
&&
!
isCategorized
)
{
else
if
(
isCustomX
()
&&
!
isCategorized
)
{
x
=
isValue
(
rawX
)
?
+
rawX
:
getXValue
(
id
,
index
);
x
=
isValue
(
rawX
)
?
+
rawX
:
getXValue
(
id
,
index
);
}
}
else
{
else
{
...
@@ -1469,12 +1469,30 @@
...
@@ -1469,12 +1469,30 @@
}
}
return
d
;
return
d
;
}
}
function
convertJsonToData
(
json
)
{
function
convertJsonToData
(
json
,
keys
)
{
var
keys
=
Object
.
keys
(
json
),
new_rows
=
[];
var
new_rows
=
[],
targetKeys
,
data
;
keys
.
forEach
(
function
(
key
)
{
if
(
keys
)
{
// when keys specified, json would be an array that includes objects
new_rows
.
push
([
key
].
concat
(
json
[
key
]));
targetKeys
=
keys
.
value
;
});
if
(
keys
.
x
)
{
return
convertColumnsToData
(
new_rows
);
targetKeys
.
push
(
keys
.
x
);
__data_x
=
keys
.
x
;
}
new_rows
.
push
(
targetKeys
);
json
.
forEach
(
function
(
o
)
{
var
new_row
=
[];
targetKeys
.
forEach
(
function
(
key
)
{
new_row
.
push
(
o
[
key
]);
});
new_rows
.
push
(
new_row
);
});
data
=
convertRowsToData
(
new_rows
);
}
else
{
Object
.
keys
(
json
).
forEach
(
function
(
key
)
{
new_rows
.
push
([
key
].
concat
(
json
[
key
]));
});
data
=
convertColumnsToData
(
new_rows
);
}
return
data
;
}
}
function
convertRowsToData
(
rows
)
{
function
convertRowsToData
(
rows
)
{
var
keys
=
rows
[
0
],
new_row
=
{},
new_rows
=
[],
i
,
j
;
var
keys
=
rows
[
0
],
new_row
=
{},
new_rows
=
[],
i
,
j
;
...
@@ -1507,7 +1525,7 @@
...
@@ -1507,7 +1525,7 @@
ids
.
forEach
(
function
(
id
)
{
ids
.
forEach
(
function
(
id
)
{
var
xKey
=
getXKey
(
id
);
var
xKey
=
getXKey
(
id
);
if
(
isCustomX
||
isTimeSeries
)
{
if
(
isCustomX
()
||
isTimeSeries
)
{
// if included in input data
// if included in input data
if
(
xs
.
indexOf
(
xKey
)
>=
0
)
{
if
(
xs
.
indexOf
(
xKey
)
>=
0
)
{
c3
.
data
.
xs
[
id
]
=
(
appendXs
&&
c3
.
data
.
xs
[
id
]
?
c3
.
data
.
xs
[
id
]
:
[]).
concat
(
c3
.
data
.
xs
[
id
]
=
(
appendXs
&&
c3
.
data
.
xs
[
id
]
?
c3
.
data
.
xs
[
id
]
:
[]).
concat
(
...
@@ -1546,7 +1564,7 @@
...
@@ -1546,7 +1564,7 @@
values
:
data
.
map
(
function
(
d
,
i
)
{
values
:
data
.
map
(
function
(
d
,
i
)
{
var
xKey
=
getXKey
(
id
),
rawX
=
d
[
xKey
],
x
=
generateTargetX
(
rawX
,
id
,
i
);
var
xKey
=
getXKey
(
id
),
rawX
=
d
[
xKey
],
x
=
generateTargetX
(
rawX
,
id
,
i
);
// use x as categories if custom x and categorized
// use x as categories if custom x and categorized
if
(
isCustomX
&&
isCategorized
&&
index
===
0
&&
rawX
)
{
if
(
isCustomX
()
&&
isCategorized
&&
index
===
0
&&
rawX
)
{
if
(
i
===
0
)
{
__axis_x_categories
=
[];
}
if
(
i
===
0
)
{
__axis_x_categories
=
[];
}
__axis_x_categories
.
push
(
rawX
);
__axis_x_categories
.
push
(
rawX
);
}
}
...
@@ -3892,7 +3910,7 @@
...
@@ -3892,7 +3910,7 @@
.
selectAll
(
'.'
+
CLASS
.
eventRect
).
remove
();
.
selectAll
(
'.'
+
CLASS
.
eventRect
).
remove
();
}
}
if
((
isCustomX
||
isTimeSeries
)
&&
!
isCategorized
)
{
if
((
isCustomX
()
||
isTimeSeries
)
&&
!
isCategorized
)
{
rectW
=
function
(
d
)
{
rectW
=
function
(
d
)
{
var
prevX
=
getPrevX
(
d
.
index
),
nextX
=
getNextX
(
d
.
index
),
dx
=
c3
.
data
.
xs
[
d
.
id
][
d
.
index
];
var
prevX
=
getPrevX
(
d
.
index
),
nextX
=
getNextX
(
d
.
index
),
dx
=
c3
.
data
.
xs
[
d
.
id
][
d
.
index
];
return
(
x
(
nextX
?
nextX
:
dx
)
-
x
(
prevX
?
prevX
:
dx
))
/
2
;
return
(
x
(
nextX
?
nextX
:
dx
)
-
x
(
prevX
?
prevX
:
dx
))
/
2
;
...
@@ -5093,10 +5111,10 @@
...
@@ -5093,10 +5111,10 @@
function
initWithUrl
(
args
)
{
function
initWithUrl
(
args
)
{
var
type
=
args
.
mimeType
?
args
.
mimeType
:
'csv'
;
var
type
=
args
.
mimeType
?
args
.
mimeType
:
'csv'
;
d3
.
xhr
(
config
.
data
.
url
,
function
(
error
,
data
)
{
d3
.
xhr
(
args
.
url
,
function
(
error
,
data
)
{
var
d
;
var
d
;
if
(
type
===
'json'
)
{
if
(
type
===
'json'
)
{
d
=
convertJsonToData
(
JSON
.
parse
(
data
.
response
));
d
=
convertJsonToData
(
JSON
.
parse
(
data
.
response
)
,
args
.
keys
);
}
else
{
}
else
{
d
=
convertCsvToData
(
data
.
response
);
d
=
convertCsvToData
(
data
.
response
);
}
}
...
@@ -5108,7 +5126,7 @@
...
@@ -5108,7 +5126,7 @@
initWithUrl
(
config
.
data
);
initWithUrl
(
config
.
data
);
}
}
else
if
(
config
.
data
.
json
)
{
else
if
(
config
.
data
.
json
)
{
init
(
convertJsonToData
(
config
.
data
.
json
));
init
(
convertJsonToData
(
config
.
data
.
json
,
config
.
data
.
keys
));
}
}
else
if
(
config
.
data
.
rows
)
{
else
if
(
config
.
data
.
rows
)
{
init
(
convertRowsToData
(
config
.
data
.
rows
));
init
(
convertRowsToData
(
config
.
data
.
rows
));
...
...
c3.min.js
View file @
c8b42c2f
This source diff could not be displayed because it is too large. You can
view the blob
instead.
htdocs/samples/data_json.html
View file @
c8b42c2f
...
@@ -3,12 +3,15 @@
...
@@ -3,12 +3,15 @@
<link
href=
"/css/c3.css"
rel=
"stylesheet"
type=
"text/css"
>
<link
href=
"/css/c3.css"
rel=
"stylesheet"
type=
"text/css"
>
</head>
</head>
<body>
<body>
<div
id=
"chart"
></div>
<div
id=
"chart1"
></div>
<div
id=
"chart2"
></div>
<script
src=
"http://d3js.org/d3.v3.min.js"
charset=
"utf-8"
></script>
<script
src=
"http://d3js.org/d3.v3.min.js"
charset=
"utf-8"
></script>
<script
src=
"/js/c3.js"
></script>
<script
src=
"/js/c3.js"
></script>
<script>
<script>
var
chart
=
c3
.
generate
({
var
chart1
=
c3
.
generate
({
bindto
:
'#chart1'
,
data
:
{
data
:
{
json
:
{
json
:
{
data1
:
[
30
,
20
,
50
,
40
,
60
,
50
],
data1
:
[
30
,
20
,
50
,
40
,
60
,
50
],
...
@@ -17,6 +20,29 @@
...
@@ -17,6 +20,29 @@
}
}
}
}
});
});
var
chart2
=
c3
.
generate
({
bindto
:
'#chart2'
,
data
:
{
// x: 'name',
json
:
[
{
id
:
1
,
name
:
'abc'
,
visits
:
200
},
{
id
:
2
,
name
:
'efg'
,
visits
:
400
},
{
id
:
3
,
name
:
'pqr'
,
visits
:
150
},
{
id
:
4
,
name
:
'xyz'
,
visits
:
420
},
],
keys
:
{
x
:
'name'
,
value
:
[
'visits'
],
}
},
axis
:
{
x
:
{
type
:
'categorized'
}
}
});
</script>
</script>
</body>
</body>
</html>
</html>
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