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

Anonymous avatarAnonymous 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

    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

    $('#chartDiv').jqPlot(...);
    

    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

    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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.