FVANCOP / ChartNew.js

MIT License
420 stars 143 forks source link

underline graphTitle text #452

Closed zoaeu12 closed 7 years ago

zoaeu12 commented 7 years ago

thanks for your awesome library. how can i make underline graphTitle?

FVANCOP commented 7 years ago

Hi,

In current version, it is not possible, however, it is possible to draw a border around the title. see https://github.com/FVANCOP/ChartNew.js/wiki/100_130_Border_and_Background_Color-for-text.

I think that I will add an option to specify which lines of the border has to be drawn. This will make possible to underline a text zone... Probably available at the end of augustus.

zoaeu12 commented 7 years ago

i added Underline Options(width, color, padding ...) and used 'setTextBordersAndBackground' function code is :

if(Underline){
    if (optiongroup == "GRAPHTITLE") {
        ctx.save();
        ctx.lineWidth = UnderlineWidth;
        ctx.strokeStyle = UnderlineColor;
        var textWidth = ctx.measureText(text).width;
        ctx.moveTo(0 - (textWidth / 2) + UnderlinePaddingX, UnderlinePaddingY);
        ctx.lineTo(textWidth - (textWidth / 2) + UnderlinePaddingX, UnderlinePaddingY);
        ctx.stroke();
        ctx.restore();
    }
}

test

it work. thank you

FVANCOP commented 7 years ago

In the last version, new options have been added. To underline the title, set option graphTitleBordersSelection to 1.

See : https://github.com/FVANCOP/ChartNew.js/wiki/100_130_Border_and_Background_Color-for-text