详情
问题
所需解决方案
图表初始化代码
function createStackedTimeSeriesChart(chartName, data, margins, tableName, ajaxPath, filterType, timeColumn, statuses, document_types, showLegend, percentage) {
if(typeof(data) == 'undefined') {
$('#' + chartName).parent().text('no data found');
return;
}
if(data.length == 0) {
$('#' + chartName).parent().text('no data found');
return;
}
try {
var maxValue = data[0]['values'][0]['x'];
var minValue = maxValue;
for(var i = 0; i < data.length; i++) {
for(var v = 0; v < data[i]['values'].length; v++) {
if(data[i]['values'][v]['x'] > maxValue) maxValue = data[i]['values'][v]['x'];
if(data[i]['values'][v]['x'] < minValue) minValue = data[i]['values'][v]['x'];
data[i]['values'][v]['x'] = new Date(data[i]['values'][v]['x']);
}
}
var chart;
nv.addGraph(function() {
chart = nv.models.stackedAreaWithFocusChart()
.useInteractiveGuideline(true)
.x(function(d) { return d['x'] })
.y(function(d) { return d['y'] })
.controlLabels({stacked: "Stacked", expanded: "Expanded"})
.duration(300)
.color(function(d){return getChartColorByValue(d)})
.showControls(false)
.showLegend(showLegend)
.clipEdge(false);
var chart_wrapper = new Chart(chartName, chart, tableName, ajaxPath, data, filterType, timeColumn, statuses, document_types);
chart_wrapper.oldest_date = moment(maxValue);
chart_wrapper.dataTable.percentage = percentage;
chart.interactiveLayer.tooltip.contentGenerator(tooltipContentGenerator(chart_wrapper));
var extentPeriod = chart_wrapper.getCurrentYearSpan();
chart.brushExtent([extentPeriod.begDate, extentPeriod.endDate]);
chart.xAxis.tickFormat(function(d) { return d3.time.format('%d/%m/%Y') (new Date(d)) });
chart.x2Axis.tickFormat(function(d) { return d3.time.format('%d/%m/%Y') (new Date(d)) });
chart.xAxis.axisLabel("date");
chart.yAxis.tickFormat(d3.format(',.0f'));
chart.y2Axis.tickFormat(d3.format(',.4f'));
chart.legend.vers('furious');
chart.legend.margin(margins);
atleastOnePoint = false;
d3.select('#' + chartName)
.datum(data)
.transition().duration(1000)
.call(chart)
.each('start', function() {
setTimeout(function() {
d3.selectAll('#' + chartName + ' *').each(function() {
if(this.__transition__)
this.__transition__.duration = 1;
})
}, 0)
});
nv.utils.windowResize(chart.update);
charts_array[chartName] = chart_wrapper;
chart.update();
chart.dispatch.on('renderEnd', function(e) { chart_wrapper.refreshDataTable(); });
return chart;
});
} catch(e) {
$('#' + chartName).parent().text(e);
}
}
答案 0 :(得分:0)
我已经通过远离TZ感知API解决了我的问题,而是切换到日期字符串。
这个解决方案比我之前尝试的更简单。