4
我正在使用Flot創建圖形。 這是這裏jsFiddle code如何獲取flot中的x軸標籤?
function drawSeriesHook(plot, canvascontext, series) {
var ctx = canvascontext,
plotOffset = plot.offset(),
labelText = 'VALUE', // customise this text, maybe to series.label
points = series.datapoints.points,
ps = series.datapoints.pointsize,
xaxis = series.xaxis,
yaxis = series.yaxis,
textWidth, textHeight, textX, textY;
// only draw label for top yellow series
if (series.color === '#F8C095') {
ctx.save();
ctx.translate(plotOffset.left, plotOffset.top);
ctx.lineWidth = series.bars.lineWidth;
ctx.fillStyle = '#000'; // customise the colour here
for (var i = 0; i < points.length; i += ps) {
if (points[i] == null) continue;
textWidth = ctx.measureText(labelText).width; // measure how wide the label will be
textHeight = parseInt(ctx.font); // extract the font size from the context.font string
textX = xaxis.p2c(points[i] + series.bars.barWidth/2) - textWidth/2;
textY = yaxis.p2c(points[i + 1]) - textHeight/2;
ctx.fillText(labelText, textX, textY); // draw the label
}
ctx.restore();
}
}
- 我drawseriesHook功能我的代碼需要得到x軸標籤像數據1,數據2,數據3,數據4
- 有什麼辦法來唯一地標識最後一個數據項不使用series.label & series.color.Currently我已經在功能
此標籤var將具有所有刻度標籤。如何單獨獲取標籤? – 2012-02-23 07:11:21
@Coder_sLaY:你不需要全部,你只需要當前的標籤? – scessor 2012-02-23 07:13:59
是的,但是當我把警報(標籤),然後我得到了所有4.我只需要第一個。 – 2012-02-23 07:19:36