www.webdeveloper.com
Results 1 to 2 of 2

Thread: Fetch value from a column to show a piechart

Hybrid View

  1. #1
    Join Date
    May 2012
    Posts
    9

    Fetch value from a column to show a piechart

    in a (using mysql)table one of my column(i.e. colour) is like :
    |Color|
    ======
    |Red |
    |Blue |
    |Green |
    |Red |
    |Green |
    |Green |
    |Red |

    With the help of jdbc connection in my current jsp page: I'm trying to show the value in a pie chart(it's wriien in jscript,where I'm putting the value from mysql) like :

    |Color|no. of Times|
    ===============
    |Red | 3 |
    |Blue | 1 |
    |Green| 3 |

    Buy I am not able to put values into the graph(I guess there is problem in by code):

    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost/apps","root","root");
    Statement stmt = con.createStatement();
    String sql2="select distinct(color) as Color from color_management order by color;";
    ResultSet rs2 = stmt.executeQuery(sql2);
    String s = rs2.getString(4);
    System.out.println(s);
    //while(rs2.get)
    String sql1 = "select count(case when color='"+s+"' then 1 end) as Color from color_management";
    ResultSet rs1 = stmt.executeQuery(sql1);
    System.out.println(sql1);
    %>


    <div id="container">


    <canvas id="chart" width="600" height="500"></canvas>

    <table id="chartData">

    <% while(rs2.next()) { %>

    <% while(rs1.next()){ %>
    <tr>
    <th>COLOR</th><th>NUMBER</th>
    </tr>

    <tr style="color: #0DA068">
    <td><%= rs2.getString(4)%></td><td><%= rs1.getString(1)%></td>
    </tr>

    <% }

    %>
    <% }

    %>

    Any inputs that how to fetch the column value in a chart where color-name as well as no. of color at a same time

  2. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,120
    First item to check is if your query returning any data, runt from mysql tools and see if it does....
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles