我想说我想增加3的移动平均线,这意味着我没有1和2的价值。谷歌图表绘制的是emty字符串,好像它是0,这在绘制图表时很难看,是否有可能阻止它?
google.charts.load('current', {
packages: ['corechart']
}).then(function () {
var data = google.visualization.arrayToDataTable([
['Day', 'Candlestick', 'Begin', 'End', 'High'],
['Mon', 20, 28, 38, 45],
['Tue', 31, 38, 55, 66],
['Wed', 50, 55, 77, 80],
['Thu', 77, 77, 66, 50],
['Fri', 68, 66, 22, 15]
]);
// add column for line, add data to rows...
var colIndex = data.addColumn('number', 'Line');
for (var i = 0; i < 2; i++) {
data.setValue(i, colIndex, "");
}
for (var i = 2; i < data.getNumberOfRows(); i++) {
data.setValue(i, colIndex, data.getValue(i, 1));
}
var options = {
height: 400,
series: {
1: {
type: 'line'
}
}
};
var chart = new google.visualization.CandlestickChart(document.getElementById('chart_div'));
chart.draw(data, options);
});
&#13;
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
&#13;
答案 0 :(得分:1)
使用值 - &gt; null
请参阅以下工作代码段...
google.charts.load('current', {
packages: ['corechart']
}).then(function () {
var data = google.visualization.arrayToDataTable([
['Day', 'Candlestick', 'Begin', 'End', 'High'],
['Mon', 20, 28, 38, 45],
['Tue', 31, 38, 55, 66],
['Wed', 50, 55, 77, 80],
['Thu', 77, 77, 66, 50],
['Fri', 68, 66, 22, 15]
]);
// add column for line, add data to rows...
var colIndex = data.addColumn('number', 'Line');
for (var i = 0; i < 2; i++) {
data.setValue(i, colIndex, null);
}
for (var i = 2; i < data.getNumberOfRows(); i++) {
data.setValue(i, colIndex, data.getValue(i, 1));
}
var options = {
height: 400,
series: {
1: {
type: 'line'
}
}
};
var chart = new google.visualization.CandlestickChart(document.getElementById('chart_div'));
chart.draw(data, options);
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
但当然,你没有有来设置任何值...
google.charts.load('current', {
packages: ['corechart']
}).then(function () {
var data = google.visualization.arrayToDataTable([
['Day', 'Candlestick', 'Begin', 'End', 'High'],
['Mon', 20, 28, 38, 45],
['Tue', 31, 38, 55, 66],
['Wed', 50, 55, 77, 80],
['Thu', 77, 77, 66, 50],
['Fri', 68, 66, 22, 15]
]);
// add column for line, add data to rows...
var colIndex = data.addColumn('number', 'Line');
for (var i = 2; i < data.getNumberOfRows(); i++) {
data.setValue(i, colIndex, data.getValue(i, 1));
}
var options = {
height: 400,
series: {
1: {
type: 'line'
}
}
};
var chart = new google.visualization.CandlestickChart(document.getElementById('chart_div'));
chart.draw(data, options);
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
答案 1 :(得分:0)
很奇怪它不能用文字值
google.charts.load('current', {
packages: ['corechart']
}).then(function () {
var data = google.visualization.arrayToDataTable([
['Day', 'Candlestick', 'Begin', 'End', 'High', 'MA'],
['Mon', 20, 28, 38, 45, null],
['Tue', 31, 38, 55, 66, null],
['Wed', 50, 55, 77, 80,40],
['Thu', 77, 77, 66, 50,40],
['Fri', 68, 66, 22, 15,40]
]);
var options = {
height: 400,
series: {
1: {
type: 'line'
}
}
};
var chart = new google.visualization.CandlestickChart(document.getElementById('chart_div'));
chart.draw(data, options);
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>