amCharts.comを試してみ
てください。シナリオを実装した JS フィドルは次のとおりです: jsfiddle.net/zeroin/gqtmN/ 凡例エントリをクリックすると、すべてのグラフが非表示になり、クリックしたグラフが表示されます。
SOが要求したソースコード:
var chart;
var chart;
var chartData = [];
function generateChartData() {
var firstDate = new Date();
firstDate.setDate(firstDate.getDate() - 60);
for (var i = 0; i < 25; i++) {
var newDate = new Date(firstDate);
newDate.setDate(newDate.getDate() + i);
var obj = {
date: newDate
};
for (var j = 0; j < 60; j++) {
obj["val" + j] = Math.round(Math.random() * (j + 1) * 10);
}
chartData.push(obj);
}
}
AmCharts.ready(function() {
generateChartData();
chart = new AmCharts.AmSerialChart();
chart.marginTop = 0;
chart.autoMarginOffset = 5;
chart.pathToImages = "http://www.amcharts.com/lib/images/";
chart.zoomOutButton = {
backgroundColor: '#000000',
backgroundAlpha: 0.15
};
chart.dataProvider = chartData;
chart.categoryField = "date";
var categoryAxis = chart.categoryAxis;
categoryAxis.parseDates = true; // as our data is date-based, we set parseDates to true
categoryAxis.minPeriod = "DD"; // our data is daily, so we set minPeriod to DD
categoryAxis.dashLength = 2;
categoryAxis.gridAlpha = 0.15;
categoryAxis.axisColor = "#DADADA";
for (var j = 0; j < 60; j++) {
var graph = new AmCharts.AmGraph();
graph.title = "series " + j;
graph.valueField = "val" + j;
graph.hidden = true;
chart.addGraph(graph);
}
chart.graphs[0].hidden = false;
var chartCursor = new AmCharts.ChartCursor();
chartCursor.cursorPosition = "mouse";
chart.addChartCursor(chartCursor);
var chartScrollbar = new AmCharts.ChartScrollbar();
chart.addChartScrollbar(chartScrollbar);
var legend = new AmCharts.AmLegend();
legend.addListener("showItem", handleAll);
chart.addLegend(legend);
chart.write("chartdiv");
});
function handleAll(event) {
for (var j = 0; j < 60; j++) {
chart.graphs[j].hidden = true;
}
event.dataItem.hidden = false;
chart.validateNow();
}
免責事項: 私は amCharts の作成者です。