admin管理员组文章数量:1295873
I'd like to overlay a label on a jqplot chart. The label should consist of text or ideally, any markup. I've examined the documentation and examples, and can't find examples of arbitrary labels in the main jqplot chart area.
Related features of jqplot: canvasOverlay is used to draw arbitrary lines on the chart. Additionally, the 'title' label exists, but sits outside the chart.
It seems like this should be simple. Some options:
- Change jqplot CSS for the main label to move it inside the chart.
- New label in jqplot.
- Problem scope is really outside jqplot, and proper solution is generic using Canvas.
Thanks in advance!
I'd like to overlay a label on a jqplot chart. The label should consist of text or ideally, any markup. I've examined the documentation and examples, and can't find examples of arbitrary labels in the main jqplot chart area.
Related features of jqplot: canvasOverlay is used to draw arbitrary lines on the chart. Additionally, the 'title' label exists, but sits outside the chart.
It seems like this should be simple. Some options:
- Change jqplot CSS for the main label to move it inside the chart.
- New label in jqplot.
- Problem scope is really outside jqplot, and proper solution is generic using Canvas.
Thanks in advance!
Share Improve this question asked Jan 22, 2013 at 22:39 Sectio AureaSectio Aurea 3936 silver badges10 bronze badges3 Answers
Reset to default 5Found a solution, posted by Chris Leonello the jqplot author to the google groups in 2010: https://groups.google./forum/?fromgroups=#!topic/jqplot-users/GDZW4BsDMiA
Chris' solution is to place this line after the plot1 code, and it works well for me.
mytitle = $('<div class="my-jqplot-title" style="position:absolute;text-align:center;padding-top: 15px;width:100%">My Custom Chart Title</div>').insertAfter('.jqplot-grid-canvas');
Try doing it in HTML5 Canvas, like this:
<script type="text/javascript">
window.addEventListener('load', function () {
// Get the canvas element.
var elem = document.getElementById('chart1');
if (!elem || !elem.getContext) {
return;
}
// Get the canvas 2d context.
var context = elem.getContext('2d');
if (!context) {
return;
}
// Let's draw "Hello world!" in blue.
context.fillStyle = '#00f';
// The font property is like the CSS font property.
context.font = 'italic 30px sans-serif';
context.textBaseline = 'top';
if (context.fillText) {
context.fillText('Hello world!', 0, 0);
}
// It looks like WebKit doesn't support the strokeText method.
// Tested on Ubuntu 8.10 Linux in WebKitGTK revision 38095 (2008-11-04, svn
// trunk build).
context.font = 'bold 30px sans-serif';
if (context.strokeText) {
context.strokeText('Hello world!', 0, 50);
}
}, false);
</script>
You can force the title over the chart using HTML tags:
title = {
text : "<div style='top:20px; left:80px; position:absolute; z-index:55;'>YOUR TITLE HERE</div>",
show : true,
fontSize : '12pt',
textAlign : 'left',
textColor : '#333',
escapeHtml : false,
}
本文标签: javascriptHow can I add text as a jqplot canvasOverlayStack Overflow
版权声明:本文标题:javascript - How can I add text as a jqplot canvasOverlay? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741618395a2388665.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论