我有一个可行的Google折线图:
btcPriceHistoryGraphInit() {
this.priceHistoryData.unshift(['Time', 'Bitcoin Price ($)']);
var graphData = this.priceHistoryData;
google.charts.setOnLoadCallback(drawMarketCapChart);
function drawMarketCapChart() {
var data = google.visualization.arrayToDataTable(graphData);
var options = {
animation: {
duration: 1000,
startup: true
},
chartArea: {
width: '85%',
height: '70%'
},
legend: {
position: 'in'
},
explorer: {
actions: ['dragToZoom', 'rightClickToReset']
},
hAxis: {
titleTextStyle: {
color: '#333'
}
},
vAxis: {
minValue: 0,
format: '$#,###'
}
};
var date_formatter = new google.visualization.DateFormat({
pattern: "MMM dd, yyyy"
});
date_formatter.format(data, 0);
var chart = new google.visualization.AreaChart(document.getElementById('price-history-graph'));
chart.draw(data, options);
}
}
现在我已将此函数/选项提取到我导入的函数中以简化它,并且google.visualization.DateFormat函数不再执行任何操作。该功能的代码如下:
export function Graph(chartDivId, chartData, xAxisLabel, yAxisLabel, vAxisFormat, chartWidthPercent, chartHeightPercent, title, animationDuration) {
var goodData = [];
chartData.forEach(function(elem) {
var num = Number(elem[1]);
goodData.push([elem[0], num])
});
var title = title || '';
var chartWidthPercent = chartWidthPercent || '85%';
var chartHeightPercent = chartHeightPercent || '70%';
var duration = animationDuration || 1000;
var vAxisFormat = vAxisFormat || '';
var xAxisLabel = xAxisLabel || '';
var yAxisLabel = yAxisLabel || '';
goodData.unshift([xAxisLabel, yAxisLabel]);
var graphData = goodData;
google.charts.setOnLoadCallback(drawMarketCapChart);
function drawMarketCapChart() {
var data = google.visualization.arrayToDataTable(graphData);
var options = {
title: title,
animation: {
duration: duration,
startup: true
},
chartArea: {
width: chartWidthPercent,
height: chartHeightPercent
},
legend: {
position: 'in'
},
explorer: {
actions: ['dragToZoom', 'rightClickToReset']
},
hAxis: {
titleTextStyle: {
color: '#333'
}
},
vAxis: {
minValue: 0,
format: vAxisFormat
}
};
var date_formatter = new google.visualization.DateFormat({
pattern: "MMM dd, yyyy"
});
date_formatter.format(data, 0);
var chart = new google.visualization.AreaChart(document.getElementById(chartDivId));
chart.draw(data, options);
}
}
我调用这样的函数:Graph( parameters )
如何让日期格式化工具正常工作?
感谢和建议
答案 0 :(得分:0)
我有一个问题,代码$j
无法正常工作。原因是$row = 4; //Dynamic number for rows
$col = 2; // Dynamic number for columns
for($i=0;$i<$row;$i++){
for($j=0;$j<$col;$j++){
echo (($i*$col)+$j+1).'<br />';
}
}
行。使用explorer.actions时,hAxis.format不起作用。