2012-06-28 1 views
-1

piechart 응용 프로그램 (here에서 도움을 얻음)을 개발 중입니다. 이제 나는 mouseover/hover에서 그 테이블을 만들었습니다.이 테이블은 다른 컬럼 값을 포함하는 다른 테이블을 보여줍니다 [tablename : widgetsold; 열 : 위젯, 판매, 이익, 구매, ..] 페이지를 새로 고치지 않고 (jsp를 사용하는 것처럼). 기능 초기화() {데이터베이스에서 데이터를 가져 와서 페이지를 새로 고치지 않고 mouseover를 사용하여 테이블에 표시합니다.

// Get the canvas element in the page 
canvas = document.getElementById('chart'); 

// Exit if the browser isn't canvas-capable 
if (typeof canvas.getContext === 'undefined') return; 

// Initialise some properties of the canvas and chart 
canvasWidth = canvas.width; 
canvasHeight = canvas.height; 
centreX = canvasWidth/2; 
centreY = canvasHeight/2; 
chartRadius = Math.min(canvasWidth, canvasHeight)/2 * (chartSizePercent/100); 

// Grab the data from the table, 
// and assign click handlers to the table data cells 

var currentRow = -1; 
var currentCell = 0; 

$('#chartData td').each(function() { 
    currentCell++; 
    if (currentCell % 2 != 0) { 
    currentRow++; 
    chartData[currentRow] = []; 
    chartData[currentRow]['label'] = $(this).text(); 
    } else { 
    var value = parseFloat($(this).text()); 
    totalValue += value; 
    value = value.toFixed(2); 
    chartData[currentRow]['value'] = value; 
    } 

    // Store the slice index in this cell, and attach a click handler to it 
    $(this).data('slice', currentRow); 
    $(this).hover(handleTableClick); 
    $(this).click(handleTableClick); 

    // Extract and store the cell colour 
    if (rgb = $(this).css('color').match(/rgb\((\d+), (\d+), (\d+)/)) { 
    chartColours[currentRow] = [ rgb[1], rgb[2], rgb[3] ]; 
    } else if (hex = $(this).css('color').match(/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/)) { 
    chartColours[currentRow] = [ parseInt(hex[1],16) ,parseInt(hex[2],16), parseInt(hex[3], 16) ]; 
    } else { 
    alert("Error: Colour could not be determined! Please specify table colours using the format '#xxxxxx'"); 
    return; 
    } 

}); 

// Now compute and store the start and end angles of each slice in the chart data 

var currentPos = 0; // The current position of the slice in the pie (from 0 to 1) 

for (var slice in chartData) { 
    chartData[slice]['startAngle'] = 2 * Math.PI * currentPos; 
    chartData[slice]['endAngle'] = 2 * Math.PI * (currentPos + (chartData[slice]['value']/totalValue)); 
    currentPos += chartData[slice]['value']/totalValue; 
} 

// All ready! Now draw the pie chart, and add the click handler to it 
drawChart(); 
$('#chart').click (handleChartClick); 

}

내 JSP 페이지 : 여기

JQuery와 있습니다 내가 AJAX의 도움으로 manysites를 통과하고 이해할 수있다

<body> 
<% 
String s1= "A"; 
String s2= "B"; 

Class.forName("com.mysql.jdbc.Driver"); 
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/apps","root","root"); 
Statement stmt = con.createStatement(); 
String sql1="select count(case when device='"+s1+"' then 1 end) as A,count(case when device='"+s2+"' then 1 end) as B from user_management;"; 

ResultSet rs1 = stmt.executeQuery(sql1); 

System.out.println(sql1); 
%> 

<div id="container"> 

<div class="wideBox"> 
<h1>Chart</h1> 
</div> 

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

<table id="chartData"> 

<% while(rs1.next()){ %> 
<tr> 
    <th>Team</th><th>Players</th> 
</tr> 

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

<tr style="color: #194E9C"> 
    <td>B</td><td><%= rs1.getString(2)%></td> 
</tr>  
<% } 

%> 

</table> 
</div> 
</body> 

, PHP는 할 수 있지만 JSP를 사용하고 있습니다. 각 행의 관련 세부 정보를 표시하기 위해 mouseover에서 다른 테이블을 표시하도록 구현하고 싶습니다.

모든 제안 사항 ...

답변

1

작은 부분으로 문제를 해결하십시오. 마우스 오버 부분은 JavaScript를 사용하여 수행 할 수 있습니다. 이것을 써서 JS에서 정의한 일부 데이터를 표시하도록하십시오. 해당 부분이 완료되면 AJAX를 사용하여 실제 데이터를 얻기 위해 테스트 데이터가 들어있는 JavaScript 부분을 업데이트 할 수 있습니다.

AJAX는 서버 측 언어로 정의해야하는 것이 아니라 사용할 수있는 기술입니다. 기계 판독 가능한 형식 (힌트 : JSON)으로 데이터를 반환하는 모든 서블릿은 JavaScript 및 AoAX로 호출 할 수 있습니다.