PDA

View Full Version : Chart problem - not make request to servlet



talha06
7 Mar 2010, 1:45 PM
Hello everyone,

In my chart application, despite I set 'url' configuration to 'JsonStore' object, it doesn't make request to servlet. So I can't see any values on my chart. I use Firebug - as most of developer use - and I can't see any requests to my servlet. :-? I'll be happy if someone can help me, thanx.

Here's my code :



Ext.onReady(function() {
Ext.QuickTips.init();

var myRec = new Ext.data.Record.create(
[{
name : 'yasAraligi',
type : 'string',
allowBlank : false
}, {
name : 'sayi',
type : 'int',
allowBlank : false
}]
);

var store = new Ext.data.JsonStore({
url : 'GetKisiYas',
root : 'rows',
fields : myRec
});

var panel = new Ext.Panel({
id : 'myPanel',
//renderTo : document.body,
renderTo : 'div1',
frame : true,
iconCls : 'chart',
title : '<b>Çal??an - Ya? Grafi?i</b>',
//autoHeight : true,
//autoWidth : true,
width : 500,
height : 300,
layout : 'fit',
items : [{
xtype : 'columnchart',
store : store,
url:'./extjs/resources/charts.swf',
xField : 'yasAraligi',
yAxis: new Ext.chart.NumericAxis({
displayName: 'YasAraligi',
labelRenderer : Ext.util.Format.numberRenderer('0,0')
}),
tipRenderer : function(chart, record, index, series){
return Ext.util.Format.number(record.data.yasAraligi, '0,0') + ' ya? aral???nda ' + record.data.sayi + ' ki?i var.';
},
chartStyle: {
padding: 10,
animationEnabled: true,
font: {
name: 'Tahoma',
color: 0x444444,
size: 11
},
dataTip: {
padding: 5,
border: {
color: 0x99bbe8,
size:1
},
background: {
color: 0xDAE7F6,
alpha: .9
},
font: {
name: 'Tahoma',
color: 0x15428B,
size: 10,
bold: true
}
},
xAxis: {
color: 0x69aBc8,
majorTicks: {color: 0x69aBc8, length: 4},
minorTicks: {color: 0x69aBc8, length: 2},
majorGridLines: {size: 1, color: 0xeeeeee}
},
yAxis: {
color: 0x69aBc8,
majorTicks: {color: 0x69aBc8, length: 4},
minorTicks: {color: 0x69aBc8, length: 2},
majorGridLines: {size: 1, color: 0xdfe8f6}
}
}, // eo chartStyle
series: [{
type: 'column',
displayName: '<b>Ki?i Say?s?</b>',
yField: 'sayi',
style: {
image:'./extjs/examples/chart/bar.gif',
mode: 'stretch',
color:0x99BBE8
}
}] // eo series
}] // eo items
});
});
Servlet : [inside of 'doGet' method]


try {
System.out.println("Servlet calisti.. TK");
int sayi1520 = 0, sayi2025 = 0, sayi2530 = 0, sayi3035 = 0, sayi3540 = 0, sayi4045 = 0, sayi45andOver = 0;
Class.forName("oracle.jdbc.OracleDriver").newInstance();
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "TALHA", "00");
Statement st = con.createStatement();

String sql = "SELECT COUNT(*) AS SAYI FROM KISI WHERE KISI_YAS>=15 AND KISI_YAS<=20";
ResultSet rs = st.executeQuery(sql);
while (rs.next()) {
sayi1520 = rs.getInt("SAYI");
}
System.out.println("15-20 yas arasi kisi sayisi : " + sayi1520);

sql = "SELECT COUNT(*) AS SAYI FROM KISI WHERE KISI_YAS>=21 AND KISI_YAS<=25";
rs = st.executeQuery(sql);
while (rs.next()) {
sayi2025 = rs.getInt("SAYI");
}
System.out.println("20-25 yas arasi kisi sayisi : " + sayi2025);

sql = "SELECT COUNT(*) AS SAYI FROM KISI WHERE KISI_YAS>=26 AND KISI_YAS<=30";
rs = st.executeQuery(sql);
while (rs.next()) {
sayi2530 = rs.getInt("SAYI");
}
System.out.println("25-30 yas arasi kisi sayisi : " + sayi2530);

sql = "SELECT COUNT(*) AS SAYI FROM KISI WHERE KISI_YAS>=31 AND KISI_YAS<=35";
rs = st.executeQuery(sql);
while (rs.next()) {
sayi3035 = rs.getInt("SAYI");
}
System.out.println("30-35 yas arasi kisi sayisi : " + sayi3035);

sql = "SELECT COUNT(*) AS SAYI FROM KISI WHERE KISI_YAS>=36 AND KISI_YAS<=40";
rs = st.executeQuery(sql);
while (rs.next()) {
sayi3540 = rs.getInt("SAYI");
}
System.out.println("35-40 yas arasi kisi sayisi : " + sayi3540);

sql = "SELECT COUNT(*) AS SAYI FROM KISI WHERE KISI_YAS>=41 AND KISI_YAS<=45";
rs = st.executeQuery(sql);
while (rs.next()) {
sayi4045 = rs.getInt("SAYI");
}
System.out.println("40-45 yas ve ustu kisi sayisi : " + sayi4045);

while (rs.next()) {
sayi45andOver = rs.getInt("SAYI");
}
System.out.println("45 yas ustu kisi sayisi : " + sayi45andOver);

JSONArray jsonArr = new JSONArray();
JSONObject json1 = new JSONObject();
JSONObject json2 = new JSONObject();
JSONObject json3 = new JSONObject();
JSONObject json4 = new JSONObject();
JSONObject json5 = new JSONObject();
JSONObject json6 = new JSONObject();
JSONObject json7 = new JSONObject();
json1.put("sayi", sayi1520);
json1.put("yasAraligi", "15-20");
json2.put("sayi", sayi2025);
json2.put("yasAraligi", "15-20");
json3.put("sayi", sayi2530);
json3.put("yasAraligi", "15-20");
json4.put("sayi", sayi3035);
json4.put("yasAraligi", "15-20");
json5.put("sayi", sayi3540);
json5.put("yasAraligi", "15-20");
json6.put("sayi", sayi4045);
json6.put("yasAraligi", "15-20");
json7.put("sayi", sayi45andOver);
json7.put("yasAraligi", "15-20");

JSONObject json = new JSONObject();
json.put("rows", jsonArr);
response.getWriter().write(json.toString());

rs.close();
st.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}

tobiu
7 Mar 2010, 5:25 PM
hi talha06,

you forgot to load the store =)

it depends on which event you want the chartpanel to (re)load the store.
if the chartpanel is a tab, you can chose activate like



,listeners : {
activate: function(){
store.load();
}
}


render, afterrender etc. will work too.


kind regards,
tobiu