是否可以使用jqPlot将图例写入单独的部门

时间:2013-05-30 09:17:35

标签: javascript jquery jqplot

我想将图例写入一个单独的div,这可能是jqPlot

legend: { 
   show: true,
   placement: 'outside',
   fontSize: '11px',
   location: 'n'
}

1 个答案:

答案 0 :(得分:0)

这是我们可以使用的两个功能:

function graphLegendCreation(cnt){
    var parentNode = _g("dmGraphLegend")//trying to get the div element with id dmGraphLegend
        , newLegendItemNode = Util.ce("span") //creating an span element
        , newLegendItemSelect = Util.cep("input", { //creating an input element
            "type":"checkbox",
            "name":"graphLegend",
            "checked":true,
            "value":cnt
        })
        , newLegendItemIconNode = Util.cep("canvas", {
            "id":"series_icon_"+cnt,
            "className":"series_icons"
        });
        newLegendItemIconNode.style.display = "inline-block";
        newLegendItemIconNode.style.position = "relative";
        if(parentNode) {
            newLegendItemNode.innerHTML = graphPlot.series[cnt].label; 
            newLegendItemSelect = Util.ac(newLegendItemSelect,parentNode);
            newLegendItemSelect.checked = true;

            Util.addEvent(newLegendItemSelect,"click", function(e) {
                graphPlot.series[this.value].show = newLegendItemSelect.checked;
                graphPlot.redraw(false);
            })
            newLegendItemIconNode = Util.ac(newLegendItemIconNode,parentNode);
            newLegendItemNode = Util.ac(newLegendItemNode,parentNode);
            Util.ac(Util.ce("br"),parentNode);
        }
}


function showlegend() {
    var cntr = 0
    ,len = 0
    ,iconNodes
    ,legendItemIconNode
    ,seriesSequence = 0
    ,context
    ,bMarker;

        iconNodes = Util.Style.g("series_icons");
        len = iconNodes.length;
        for(cntr = 0; cntr < len; cntr++) {
            legendItemIconNode = iconNodes[cntr];
            if ($.browser.msie) {
                G_vmlCanvasManager.initElement(legendItemIconNode);
            }
            context = legendItemIconNode.getContext('2d');
            bMarker = new nMarkerRenderer({
                size:8,
                color:graphPlot.series[cntr].color,
                style:graphPlot.series[cntr].markerOptions.style
            });
            bMarker.draw(12,12,context, {});
        }

}

CSS: .series_icons {宽度:20像素;高度:20像素;}

每次在图例中创建条目时,必须调用GraphLegendCreation函数。 ShowLegend就是要创建那个传奇图标。

&#34; nMarkrenderer&#34;已经是一个已定义的函数。从jsfiddle file

获取该功能

请告诉我您需要更多帮助。它确实适用于IE。经过试验和测试