Search code examples
jqueryjquery-pluginsjqplot

JQPlot - No plot target specified


I'm trying to draw jqplot with the following code:

<script lang="javascript" type="text/javascript">
    $(document).ready(function () {



        var line1 = var line1 =[["10.01.2011",3.9990],["11.01.2011",3.9910],["12.01.2011",4.0140],["13.01.2011",3.9940],["14.01.2011",3.9050],["17.01.2011",3.9340],["18.01.2011",3.9520],["19.01.2011",3.8980],["20.01.2011",3.8690],["21.01.2011",3.8830],["24.01.2011",3.8550],["25.01.2011",3.8480],["26.01.2011",3.8190],["27.01.2011",3.8440],["28.01.2011",3.8260],["31.01.2011",3.8060],["01.02.2011",3.7970],["02.02.2011",3.8060],["03.02.2011",3.8110],["04.02.2011",3.8640],["07.02.2011",3.8750],["08.02.2011",3.8640],["09.02.2011",3.8480],["11.02.2011",3.8570],["14.02.2011",3.8880],["15.02.2011",3.88],["16.02.2011",3.8520],["17.02.2011",3.8590],["18.02.2011",3.8690],["22.02.2011",3.8440],["23.02.2011",3.8080],["24.02.2011",3.7410],["25.02.2011",3.7460],["28.02.2011",3.7550],["01.03.2011",3.7520],["02.03.2011",3.76],["03.03.2011",3.7420],["04.03.2011",3.7430],["07.03.2011",3.7330],["08.03.2011",3.7260],["09.03.2011",3.76],["10.03.2011",3.7910],["11.03.2011",3.79]]; 

        var plot1 = $.jqplot('chart1', [line1], {
            title: 'Default Date Axis',
            axes: { xaxis: { renderer: $.jqplot.DateAxisRenderer } },
            series: [{ lineWidth: 4, markerOptions: { style: 'square' } }]
        });
    });
</script>

It is generated through some C# code, but at the end the page source looks like the presented code. The chart is not drawn and jquery throws this exception: No plot target specified.

Any clue for that?


Solution

  • Be sure that your HTML includes an element (usually a div) with an Id of chart1.

    The jqplot source code goes like this:

    this.init = function(target, data, options) {
    
        this.target = $('#'+target);
    
        ....
    
        if (!this.target.get(0)) {
            throw "No plot target specified";
        }
    
        ....
    }
    

    It appears that is the only place in the code that particular error occurs. Note that the # character is prepended to the target, hence why target needs to be a valid Id.