Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7743561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:33:58+00:00 2026-06-01T09:33:58+00:00

I am using a switch-statement to switch between modes on a the jqPlot jQuery

  • 0

I am using a switch-statement to switch between modes on a the jqPlot jQuery plugin.

How can I apply my value from the switch to the function parameters?

I have

type = detectType(gType);

I need this to display, where type is in the parameters below. It does not return that value:

function detectType(value){
    switch(value){
        case 'bar':
            return 'renderer:$.jqplot.BarRenderer,';
            break;
        case 'pie':
            return 'renderer: $.jqplot.PieRenderer,';
            break;
    }
}

function generateGraph(id,gType) {
    type = detectType(gType);
    var s1 = [2, 6, 7, 10];
    var s2 = [7, 5, 3, 4];
    var s3 = [14, 9, 3, 8];

$.jqplot(''+id+'', [s1, s2, s3], {
        stackSeries: true,
        captureRightClick: true,
        seriesDefaults: {
            type
            rendererOptions: {
                barMargin: 30,
                highlightMouseDown: true   
            },
            pointLabels: {
                show: true
            }
        },
        axes: {
            xaxis: {
                renderer: $.jqplot.CategoryAxisRenderer
            },
            yaxis: {
                padMin: 0
            }
        },
        legend: {
           show: true,
           location: 's',
           placement: 'outside'
        }
    });
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:34:00+00:00Added an answer on June 1, 2026 at 9:34 am

    You can’t do what you’re trying to do with the type string. It’s invalid syntax.

    Instead, detectType should just return the renderer object itself, not as a string. Then, assign that to renderer in your series defaults. Like so:

    function detectType(value){
        switch(value){
            case 'bar':
                return $.jqplot.BarRenderer;
    
            case 'pie':
                return $.jqplot.PieRenderer;
        }
    }
    

    Then:

    //...
    seriesDefaults: {
        renderer: type
        //...
    }
    //...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For as long as I can remember I have avoided using switch statement fall-through.
When using a switch() statement, you add break; in between separate case: declarations. But
currently i'm attempting to using a switch statement to change between time zone with
I have a switch statement in my action script class.I have a function onKeyDown(event:
I have recently learned that you can use a neat switch statement with fallthrough
How to write following statement in c using switch statement in c int i
What's the best practice for using a switch statement vs using an if statement
What is the benefit/downside to using a switch statement vs. an if/else in C#.
I'm programming a simple text-based RPG using a switch statement for a game loop.
Im really trying to keep my code clean by using the switch statement but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.