2013-01-22 23 views
4

我想覆蓋jqplot圖表上的標籤。標籤應由文字或理想的標記組成。我已檢查了documentationexamples,並且無法在主要jqplot圖表區域中找到任意標籤的示例。如何將文本添加爲​​jqplot canvasOverlay?

jqplot的相關特性:canvasOverlay用於在圖表上繪製任意線條。此外,「標題」標籤存在,但位於圖表外。

看起來這應該很簡單。一些選項:

  1. 將主標籤的jqplot CSS更改爲在圖表內移動它。
  2. jqplot中的新標籤。
  3. 問題範圍真的超出了jqplot,正確的解決方案是使用Canvas的通用解決方案。

在此先感謝!

回答

3

嘗試在HTML5畫布做,就像這樣:

<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> 
+1

不幸的是,這不會導致我的圖表div中的任何可見的呈現。感謝這個例子。 –

3

找到了解決方案,張貼克里斯Leonello的jqplot筆者給谷歌集團在2010年:https://groups.google.com/forum/?fromgroups=#!topic/jqplot-users/GDZW4BsDMiA

克里斯的解決方案是將這條線在plot1代碼之後,對我來說效果很好。

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');