2016-08-30 2 views
0

그래프를 그릴 때 아래 코드를 작성했습니다. 이름 : Test1.zul변수를 zscript에서 javascript로 전달하는 방법

<?page title="new page title" contentType="text/html;charset=UTF-8"?> 
<zk xmlns:n="native"> 
<window border="normal"> 
<html> 
<head> 
<meta charset="utf-8"/> 
<meta name="viewport" content="width=device-width, initial-scale=1"/> 
<title>Trinet</title> 
<link rel="stylesheet" href="http://fonts.googleapis.com/css? family=Open+Sans:300,400,700"/> 
<h4 backgroung-color="#800000"> 
<a href="Test1.zul"> <img src="Image/5.png" style="width:200px;height:50px;float:left;"/></a></h4> 
<h2 align="center">TriNet Automation Platform</h2> 
<h5 align="right"> 
Welcome Administrator 
</h5> 
</head> 

<body> 

    <div > 

    <li data-filtertext="Homepage"><a href="Test1.zul">Home</a></li> 
    <li data-filtertext="Create Job"><a href="" data-ajax="false">Create Job</a></li> 
<li data-filtertext="Job progress"><a href="" data-ajax="false">Job Progress</a></li> 
<li data-filtertext="Scripting"><a href="" data-ajax="false">Scripting</a>   </li> 
<li data-filtertext="Report"><a href="" data-ajax="false">Report</a></li> 
<li data-filtertext="Locators"><a href="" data-ajax="false">Locators</a></li> 
<li data-filtertext="VM Management"><a href="" data-ajax="false">VM Management</a></li> 
<li data-filtertext="Options"><a href="" data-ajax="false">Options</a></li> 


    </div> 



    <!--Divs that will hold the charts--> 
    <table class="columns"> 
    <tr> 
    <td> 
    <div class = "MyForm1" style="border: solid 2px #000000; width:auto; height:300px;" align="center"> 
    <form> 
    <table> 
<tr> 
<td> 
    <select id="Projects"> 
<option value = "0" selected = "1">Select Project</option> 
<option value="Project 1">Project 1</option> 
<option value="Project 2">Project 2</option> 
<option value="Project 3">Project 3</option> 
<option value="Project 4">Project 4</option> 
<option value="Project 5">Project 5</option> 
    </select> 
</td> 
<td> 
    <select id="ChartType" name="ChartType" onchange="drawChart()"> 
<option value = "PieChart">Select Chart Type </option> 
<option value="PieChart">PieChart </option> 
<option value="Histogram">Histogram </option> 
<option value="LineChart">LineChart </option> 
<option value="BarChart">BarChart </option> 
    </select> 
    </td> 
    </tr> 

    </table> 
<table> 
<tr> 
<select id="Version"> 
<option value = "0" selected = "1">Select Version</option> 
<option value="Version 1">Version 1</option> 
<option value="Version 2">Version 2</option> 
<option value="Version 3">Version 3</option> 
<option value="Version 4">Version 4</option> 
<option value="Version 5">Version 5</option> 
    </select> 
</tr> 

</table>  
    </form> 
    </div> 
    </td> 
    <td><div id="chart_div" style="border: solid 2px #000000;" ></div> 
    </td> 
    <td><div id="chart_div2" style="border: solid 2px #000000;"></div></td> 
    </tr> 
    <tr> 
    <td><div id="chart_div3" style="border: solid 2px #000000;"></div></td> 
    <td><div id="chart_div4" style="border: solid 2px #000000;"></div></td> 
    <td><div id="chart_div5" style="border: solid 2px #000000;"></div></td> 
    </tr> 
    </table> 
      <!--Load the AJAX API--> 
    <script type="text/javascript" src="https://www.google.com/jsapi"> </script> 
    <script type="text/javascript"> 

     // Load the Visualization API and the piechart package. 
     google.load('visualization', '1.0', {'packages':['corechart']}); 

     // Set a callback to run when the Google Visualization API is loaded. 
     google.setOnLoadCallback(drawChart); 

     // Callback that creates and populates a data table, 
     // instantiates the pie chart, passes in the data and 
     // draws it. 

     function drawChart() { 

     // Create the data table. 
     var data = new google.visualization.DataTable(); 
     data.addColumn('string', 'Test Case');  
     data.addColumn('number', 'Total Number'); 
     data.addRows([ 
      ['Total Test Case', 50], 
      ['Test Case Executed', 30], 
      ['Failed Test Case', 08], 
      ['Test Case Not Executed', 5], 
     ]); 
     // Create the data table. 
     var data2 = new google.visualization.DataTable(); 
     data2.addColumn('string', 'Topping'); 
     data2.addColumn('number', 'Slices'); 
     data2.addRows([ 
      ['Mushrooms', 3], 
      ['Onions', 1], 
      ['Olives', 15], 
      ['Zucchini', 1], 
      ['Pepperoni', 2] 
     ]); 

     var data3 = new google.visualization.DataTable(); 
     data3.addColumn('string', 'Year'); 
     data3.addColumn('number', 'Sales'); 
     data3.addColumn('number', 'Expenses'); 
     data3.addRows([ 
      ['2004', 1000, 400], 
      ['2005', 1170, 460], 
      ['2006', 860, 580], 
      ['2007', 1030, 540] 
     ]); 

     var data4 = new google.visualization.DataTable(); 
     data4.addColumn('string', 'Year'); 
     data4.addColumn('number', 'Sales'); 
     data4.addColumn('number', 'Expenses'); 
     data4.addRows([ 
      ['2004', 1000, 400], 
      ['2005', 1170, 460], 
      ['2006', 860, 580], 
      ['2007', 1030, 540] 
     ]); 

     var data5 = new google.visualization.DataTable(); 
     data5.addColumn('string', 'Year'); 
     data5.addColumn('number', 'Sales'); 
     data5.addColumn('number', 'Expenses'); 
     data5.addRows([ 
      ['2004', 1000, 400], 
      ['2005', 1170, 460], 
      ['2006', 860, 580], 
      ['2007', 1030, 540] 
     ]); 

     // Set chart options 
     var options = {'title':'Test Case Details', 
         'width':400, 
         'height':300}; 
     // Set chart options 
     var options2 = {'title':'Test Case Details', 
         'width':400, 
         'height':300}; 
     // Set chart options 
     var options3 = {'title':'Weekly Release', 
         'width':400, 
         'height':300}; 
     // Set chart options 
     var options4 = {'title':'Monthly Release', 
         'width':400, 
         'height':300}; 
     // Set chart options       
     var options5 = {'title':'Automation Cost Saving', 
         'width':400, 
         'height':300}; 

     // Instantiate and draw our chart, passing in some options. 
     var chart = new google.visualization[document.getElementById("ChartType").value](document.getElementById('chart_div')); 
     chart.draw(data, options); 
     var chart2 = new google.visualization.Histogram(document.getElementById('chart_div2')); 
     chart2.draw(data2, options2); 
     var chart3 = new google.visualization.LineChart(document.getElementById('chart_div3')); 
     chart3.draw(data3, options3); 
     var chart4 = new google.visualization.LineChart(document.getElementById('chart_div4')); 
     chart4.draw(data4, options4); 
     var chart5 = new google.visualization.BarChart(document.getElementById('chart_div5')); 
     chart5.draw(data5, options5); 

     } 
    </script> 


    </body> 

</html> 

</window> 
</zk> 

여기 값을 그래프로 자바 스크립트를 통해 전달합니다. 그러나 데이터베이스를 통해 그래프에 값을 전달해야합니다. 값을 검색하는 코드도 작성했습니다. 이름은 : 여기 Test2.zul에서 데이터베이스 즉에서 값을 고려하여 작성되어야 Test1.zul 및 그래프에 Test2.zul에서 값을 전달하려는

<?page title="new page title" contentType="text/html;charset=UTF-8"?> 
<zk> 
<window title="JDBC demo" border="normal"> 

<zscript><![CDATA[ 

import java.sql.*; 

String submit() { 
    //load driver and get a database connetion 
    // Class.forName("com.mysql.jdbc.Driver"); 
    // Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3309/graphvalue","root","root"); 
    // PreparedStatement stmt = null; 
     Class.forName("com.mysql.jdbc.Driver"); 
     Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3309/graphvalue","root","root"); 
     Statement stmt; 
     ResultSet rs; 
     String s1; 
     int a,b,c,d; 
    try { 
     // stmt = conn.prepareStatement("select * from TestCase"); 
     //insert what end user entered into database table 
     // stmt.setString(1, name.value); 
     // stmt.setString(2, email.value); 
     //stmt.getString(1, name.value); 

     //execute the statement 
    // String abc = stmt.executeUpdate(); 
    // System.out.println(abc+ " "); 
     stmt=conn.createStatement(); 
     rs=stmt.executeQuery("select * from TestCase"); 
     while(rs.next()) 
      System.out.println(rs.getString(1)+" "+rs.getInt(2)+" "+rs.getInt(3)+" "+rs.getInt(4)+" "+rs.getInt(5)); 

     rs.first(); 
     s1=rs.getString(1); 
     System.out.println(s1); 
     // b=rs.getInt(2); 
     conn.close(); 


    } finally { //cleanup 

     if (stmt != null) { 
      try { 
       stmt.close(); 
      } catch (SQLException ex) { 
       log.error(ex); //log and ignore 
      } 
     } 
     if (conn != null) { 
      try { 
       conn.close(); 
      } catch (SQLException ex) { 
       log.error(ex); //log and ignore 
      } 
     } 
    } 
    return s1; 
} 
]]> 

</zscript> 
<vbox> 
    <button label="submit" onClick="submit()"/> 
</vbox> 
1:${s1}; //To display the value of s1 (its not working) 
</window> 
</zk> 

Test2.zul

. 데이터베이스 값은 다음과 같습니다

ProjectName TotalTestCase TestCaseExecuted TestCaseFailed TestCaseNotExecuted Project1 50 30 8 20 Project2 20 10 2 10 Project3 55 25 12 30

는 제가 진행하는 방법을 알려 주시기 바랍니다. 고맙습니다

답변

0

다양한 방법으로 zscript에서 구성 요소에 액세스 할 수 있습니다. here 또는 here 설명서를 참조하십시오.

당신은, 예를 들어, 단순히 ID로 구성 요소를 참조하고이 예에서와 같이 값을 설정할 수 있습니다 :

<window id="win_1"> 
    <zscript><![CDATA[ 
     win_1.title="given by zscript";    
    ]]> 
    </zscript>  
</window> 

를 또는 구성 요소에 zscript를 추가하고 사용 self :

<listbox> 
    <zscript>self.getItems();</zscript><!-- self is listbox --> 
    <listitem value="ab" label="${self.value}"/><!-- self is listitem --> 
    <zscript>self.getSelectedIndex();</zscript><!-- self is listbox --> 
</listbox> 
관련 문제