I am using d3 chart library for my project Also,i am able to create my PCP successfully with JSON data set. But I am having a requirement for grouping the data set as mentioned below:
In the above screen A to E is one group then some space and F to J is one group.This grouping is always fixed.Also i have mentioned the code which i am using right now:
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>Parallel Coordinates </title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<script>
var m = [200, 30, 50, 150],
w = 1500 - m[1] - m[3],
h = 800 - m[0] - m[2];
var x = d3.scale.ordinal().rangePoints([0, w], 1),
y = {},
dragging = {};
var line = d3.svg.line(),
axis = d3.svg.axis().orient("left"),
background,
foreground;
var color = d3.scale.ordinal()
.domain([1,2,3])
.range(['red','green','blue']);
//var color = function(d) { return green_to_blue(d['Plant']); };
var svg = d3.select("body").append("svg:svg")
.attr("width", w + m[1] + m[3])
.attr("height", h + m[0] + m[2])
.append("svg:g")
.attr("transform", "translate(" + m[3] + "," + m[0] + ")");
var data = [{
"Plant": "American Blueberry",
"A": 0.2,
"B": 3,
"C": 23,
"D": 432,
"E": 123,
"F": 74,
"G": 1231,
"H": 14,
"I": 43,
"J": 675
}, {
"Plant": "American Blueberry5",
"A": 0.2,
"B": 3,
"C": 23,
"D": 432,
"E": 123,
"F": 74,
"G": 1231,
"H": 14,
"I": 3,
"J": 675
}, {
"Plant": "Blueberry1",
"A": 0.2,
"B": 3,
"C": 23,
"D": 432,
"E": 123,
"F": 74,
"G": 1231,
"H": 14,
"I": 43,
"J": 675
}, {
"Plant": "American Blueberry2",
"A": 0.2,
"B":100,
"C": 50,
"D": 40,
"E": 90,
"F": 88,
"G": 231,
"H": 14,
"I": 43,
"J": 675
}];
// Extract the list of dimensions and create a scale for each.
x.domain(dimensions = d3.keys(data[0]).filter(function(d) {
if (d === "name") return false;
if (d === "Plant" || d === "Chemical" || d === "Pathway" || d === "Gene" || d === "Disease") {
y[d] = d3.scale.ordinal()
.domain(data.map(function(p) {
return p[d];
}))
.rangePoints([h, 0]);
} else {
y[d] = d3.scale.linear()
.domain(d3.extent(data, function(p) {
return +p[d];
}))
.range([h, 0]);
}
return true;
}));
// Add grey background lines for context.
background = svg.append("svg:g")
.attr("class", "background")
.selectAll("path")
.data(data)
.enter().append("svg:path")
.attr("d", path);
// Add blue foreground lines for focus.
foreground = svg.append("svg:g")
.attr("class", "foreground")
.selectAll("path")
.data(data)
.enter().append("svg:path")
.attr("d", path)
.attr('stroke', function(d) { return color(d.label); });
// Add a group element for each dimension.
var g = svg.selectAll(".dimension")
.data(dimensions)
.enter().append("svg:g")
.attr("class", "dimension")
.attr("transform", function(d) {
return "translate(" + x(d) + ")";
})
.call(d3.behavior.drag()
.on("dragstart", function(d) {
dragging[d] = this.__origin__ = x(d);
background.attr("visibility", "hidden");
})
.on("drag", function(d) {
dragging[d] = Math.min(w, Math.max(0, this.__origin__ += d3.event.dx));
foreground.attr("d", path);
dimensions.sort(function(a, b) {
return position(a) - position(b);
});
x.domain(dimensions);
g.attr("transform", function(d) {
return "translate(" + position(d) + ")";
})
})
.on("dragend", function(d) {
delete this.__origin__;
delete dragging[d];
transition(d3.select(this)).attr("transform", "translate(" + x(d) + ")");
transition(foreground)
.attr("d", path);
background
.attr("d", path)
.transition()
.delay(500)
.duration(0)
.attr("visibility", null);
}));
// Add an axis and title.
g.append("svg:g")
.attr("class", "axis")
.each(function(d) {
d3.select(this).call(axis.scale(y[d]));
})
.append("svg:text")
.attr("text-anchor", "middle")
.attr("y", -9)
.text(String);
// Add and store a brush for each axis.
g.append("svg:g")
.attr("class", "brush")
.each(function(d) {
d3.select(this).call(y[d].brush = d3.svg.brush().y(y[d]).on("brush", brush));
})
.selectAll("rect")
.attr("x", -8)
.attr("width", 16);
function position(d) {
var v = dragging[d];
return v == null ? x(d) : v;
}
function transition(g) {
return g.transition().duration(500);
}
// Returns the path for a given data point.
function path(d) {
return line(dimensions.map(function(p) {
return [position(p), y[p](d[p])];
}));
}
// Handles a brush event, toggling the display of foreground lines.
function brush() {
var actives = dimensions.filter(function(p) {
return !y[p].brush.empty();
}),
extents = actives.map(function(p) {
return y[p].brush.extent();
});
foreground.style("display", function(d) {
return actives.every(function(p, i) {
return extents[i][0] <= d[p] && d[p] <= extents[i][1];
}) ? null : "none";
});
}
</script>
</body>
</html>