Canvas 如何使用jQuery.flot.js在我的图表中填充点上的文本?

Canvas 如何使用jQuery.flot.js在我的图表中填充点上的文本?,canvas,html5-canvas,flot,Canvas,Html5 Canvas,Flot,我用来画我的图表,我想画一个圆圈,上面有一些文字在我的数据中,我在点中使用符号属性,我的代码如下: points: { show: true, symbol: self.drawSymbol, fillColor: 'blue' }, drawSymbol: function(ctx, x, y, radius, shadow) {

我用来画我的图表,我想画一个圆圈,上面有一些文字在我的数据中,我在点中使用符号属性,我的代码如下:

 points: {
                    show: true,
                    symbol: self.drawSymbol,
                    fillColor: 'blue'
                },
 drawSymbol: function(ctx, x, y, radius, shadow) {
        ctx.arc(x, y, 15, 0, 2 * Math.PI, false);
        ctx.fill('65kg',x,y);
    },
这并不是所有的代码,每次绘制数据时调用的drawSymbol方法,我的图表没有按照我的预期显示

你看,文字被圆圈覆盖了,这怎么会发生呢

如何根据我的观点画一篇文章


还有其他解决方案吗?

在flots点绘制例程中,它调用自定义符号函数(在您的情况下,该函数写入文本),然后(在顶部)用蓝色填充符号。要执行您想要的操作,您必须禁用flots fill,并在编写文本之前在
drawSymbol
中自己填充

在您的选项中:

points: {
    show: true,
    symbol: drawSymbol,
    fill: false // disable flots fill
},
并将您的drawSymbol修改为:

var drawSymbol = function(ctx, x, y, radius, shadow) {
   ctx.arc(x, y, 15, 0, 2 * Math.PI, false);
   ctx.fillStyle = "blue";
   ctx.fill(); // fill it yourself
   ctx.font = "12px 'Segoe UI'";
   ctx.fillStyle = "white";
   ctx.textAlign = 'center';
   ctx.fillText('65kg', x, y + 4); //now the text
}
这是一把小提琴

要从
drawSymbol
访问数据,请执行以下操作:

var drawSymbol = function(ctx, x, y, radius, shadow) {
    // keep track of how many times you've called this
    if (this.numCalls == undefined){
       this.numCalls = -1;
    }
    this.numCalls++;
    // flot "over" draws
    // so always keep the index correct...
    if (this.numCalls >= someData[0].data.length){
        this.numCalls = this.numCalls - someData[0].data.length;
   }
   //console.log(this.numCalls);
   ctx.arc(x, y, 15, 0, 2 * Math.PI, false);
   ctx.fillStyle = "blue";
   ctx.fill();
   ctx.font = "12px 'Segoe UI'";
   ctx.fillStyle = "white";
   ctx.textAlign = 'center';
   // access your data point
   ctx.fillText(someData[0].data[this.numCalls][3]+'kg', x, y + 4);
}

更新。

在flots点绘制例程中,它调用自定义符号函数(在您的情况下,该函数写入文本),然后(在顶部)用蓝色填充符号。要执行您想要的操作,您必须禁用flots fill,并在编写文本之前在
drawSymbol
中自己填充

在您的选项中:

points: {
    show: true,
    symbol: drawSymbol,
    fill: false // disable flots fill
},
并将您的drawSymbol修改为:

var drawSymbol = function(ctx, x, y, radius, shadow) {
   ctx.arc(x, y, 15, 0, 2 * Math.PI, false);
   ctx.fillStyle = "blue";
   ctx.fill(); // fill it yourself
   ctx.font = "12px 'Segoe UI'";
   ctx.fillStyle = "white";
   ctx.textAlign = 'center';
   ctx.fillText('65kg', x, y + 4); //now the text
}
这是一把小提琴

要从
drawSymbol
访问数据,请执行以下操作:

var drawSymbol = function(ctx, x, y, radius, shadow) {
    // keep track of how many times you've called this
    if (this.numCalls == undefined){
       this.numCalls = -1;
    }
    this.numCalls++;
    // flot "over" draws
    // so always keep the index correct...
    if (this.numCalls >= someData[0].data.length){
        this.numCalls = this.numCalls - someData[0].data.length;
   }
   //console.log(this.numCalls);
   ctx.arc(x, y, 15, 0, 2 * Math.PI, false);
   ctx.fillStyle = "blue";
   ctx.fill();
   ctx.font = "12px 'Segoe UI'";
   ctx.fillStyle = "white";
   ctx.textAlign = 'center';
   // access your data point
   ctx.fillText(someData[0].data[this.numCalls][3]+'kg', x, y + 4);
}

更新。

在flots点绘制例程中,它调用自定义符号函数(在您的情况下,该函数写入文本),然后(在顶部)用蓝色填充符号。要执行您想要的操作,您必须禁用flots fill,并在编写文本之前在
drawSymbol
中自己填充

在您的选项中:

points: {
    show: true,
    symbol: drawSymbol,
    fill: false // disable flots fill
},
并将您的drawSymbol修改为:

var drawSymbol = function(ctx, x, y, radius, shadow) {
   ctx.arc(x, y, 15, 0, 2 * Math.PI, false);
   ctx.fillStyle = "blue";
   ctx.fill(); // fill it yourself
   ctx.font = "12px 'Segoe UI'";
   ctx.fillStyle = "white";
   ctx.textAlign = 'center';
   ctx.fillText('65kg', x, y + 4); //now the text
}
这是一把小提琴

要从
drawSymbol
访问数据,请执行以下操作:

var drawSymbol = function(ctx, x, y, radius, shadow) {
    // keep track of how many times you've called this
    if (this.numCalls == undefined){
       this.numCalls = -1;
    }
    this.numCalls++;
    // flot "over" draws
    // so always keep the index correct...
    if (this.numCalls >= someData[0].data.length){
        this.numCalls = this.numCalls - someData[0].data.length;
   }
   //console.log(this.numCalls);
   ctx.arc(x, y, 15, 0, 2 * Math.PI, false);
   ctx.fillStyle = "blue";
   ctx.fill();
   ctx.font = "12px 'Segoe UI'";
   ctx.fillStyle = "white";
   ctx.textAlign = 'center';
   // access your data point
   ctx.fillText(someData[0].data[this.numCalls][3]+'kg', x, y + 4);
}

更新。

在flots点绘制例程中,它调用自定义符号函数(在您的情况下,该函数写入文本),然后(在顶部)用蓝色填充符号。要执行您想要的操作,您必须禁用flots fill,并在编写文本之前在
drawSymbol
中自己填充

在您的选项中:

points: {
    show: true,
    symbol: drawSymbol,
    fill: false // disable flots fill
},
并将您的drawSymbol修改为:

var drawSymbol = function(ctx, x, y, radius, shadow) {
   ctx.arc(x, y, 15, 0, 2 * Math.PI, false);
   ctx.fillStyle = "blue";
   ctx.fill(); // fill it yourself
   ctx.font = "12px 'Segoe UI'";
   ctx.fillStyle = "white";
   ctx.textAlign = 'center';
   ctx.fillText('65kg', x, y + 4); //now the text
}
这是一把小提琴

要从
drawSymbol
访问数据,请执行以下操作:

var drawSymbol = function(ctx, x, y, radius, shadow) {
    // keep track of how many times you've called this
    if (this.numCalls == undefined){
       this.numCalls = -1;
    }
    this.numCalls++;
    // flot "over" draws
    // so always keep the index correct...
    if (this.numCalls >= someData[0].data.length){
        this.numCalls = this.numCalls - someData[0].data.length;
   }
   //console.log(this.numCalls);
   ctx.arc(x, y, 15, 0, 2 * Math.PI, false);
   ctx.fillStyle = "blue";
   ctx.fill();
   ctx.font = "12px 'Segoe UI'";
   ctx.fillStyle = "white";
   ctx.textAlign = 'center';
   // access your data point
   ctx.fillText(someData[0].data[this.numCalls][3]+'kg', x, y + 4);
}

更新。

如果我想将数据传递给drawSymbol方法,该怎么办?我希望点上的文本与我传递给yaxis的数据相同,但我检查drawSymbol是否没有我的数据参数,我该怎么办?@JackZhang,这很难。我将全局存储数据,然后根据调用drawSymbol例程的次数进行访问,请参见上面的更新答案。如果我想将数据传递给drawSymbol方法,该怎么办?我希望点上的文本与我传递给yaxis的数据相同,但我检查drawSymbol是否没有我的数据参数,我该怎么办?@JackZhang,这很难。我将全局存储数据,然后根据调用drawSymbol例程的次数进行访问,请参见上面的更新答案。如果我想将数据传递给drawSymbol方法,该怎么办?我希望点上的文本与我传递给yaxis的数据相同,但我检查drawSymbol是否没有我的数据参数,我该怎么办?@JackZhang,这很难。我将全局存储数据,然后根据调用drawSymbol例程的次数进行访问,请参见上面的更新答案。如果我想将数据传递给drawSymbol方法,该怎么办?我希望点上的文本与我传递给yaxis的数据相同,但我检查drawSymbol是否没有我的数据参数,我该怎么办?@JackZhang,这很难。我将全局存储数据,然后根据您调用drawSymbol例程的次数进行访问,请参见上面的更新答案。