1. Chris Leonello
  2. jqplot
Issue #114 open

$.jqplot(target,...) should accept any element, jQuery selection, or jQuery selector as target.

Anonymous created an issue

$.jqplot() currently only accepts one id as the target. This doesn't work well for cases where the target has no id. Sometimes you want to create an anonymous element and draw a plot inside, but the current implementation makes this very difficult.

Comments (10)

  1. Anonymous

    The current way of interpretting target as id goes against POLS, as jQuery plugins are expected to work on jQuery selectors. The biggest problem is that doing $.jqplot('#someid',...) completely breaks because the jqplot requires the id without the # in front. The fix should be just a simple change in jqplot.core.js:

              this.init = function(target, data, options) {
                 for (var i=0; i<$.jqplot.preInitHooks.length; i++) {
                     $.jqplot.preInitHooks[i].call(this, target, data, options);
    -            this.targetId = target;
    -            this.target = $('#'+target);
    +            if (typeof(target) == 'string' && target[0] != '#')
    +              this.target = $('#'+target);
    +            else
    +              this.target = $(target);
                 if (!this.target.get(0)) {
                     throw "No plot target specified";
  2. Chris Leonello repo owner

    POLS? It shouldn't really be a surprise, since it is well documented in many places how to use the plugin ;-)

    In any case, I've been planning how to enhance jqPlot to accept jQuery selectors as arguments as well as how work directly on a selector. This would mean you could do things like:

    var myChart = $('div.chart-class');
    $.jqplot(myChart, ...);



    or, as you suggest,

    $.jqplot('#chartDiv', ...);
  3. Anonymous

    Regarding issue #113 (bitbucket does not allow commenting on issue #113):

    I think $.widget implements other behaviors, such as method calling and value setting, that do not specifically deal with the target issue. For example, $('elem').jqplot('reDraw') would be $.widget's conventional way of calling the reDraw() function. Is this also something you had in mind?

  4. Chris Leonello repo owner

    Your comments seemed to come through on #113. Here is my response:

    I hadn't yet considered implementing jquery-ui specific calling conventions for plot methods. I'm not guaranteeing any specific functionality at this time, only that I'm expanding plot constructor functionality and that could include the jquery-ui convention. I'll have to investigate.

    For the time being, I'm going to roll them into one issue while I determine feasibility and possibilities.

  5. Reuben Bond

    The need for each plot to have a unique id, rather than just being any element, causes difficulty when it comes to making dynamic sites using jqplot. Any thoughts on improving this behaviour?

  6. Daniel Zenker

    Is it still planned to offer the original feature request? I just came by the same problem and recognized it's marked as an open feature request with high priority since 2009 - in any case, I'd be delighted if this feature is still on the agenda :)

  7. Log in to comment