Ext Flot dynamically change chart values - extjs

I am using Ext flot for drawing charts on my application. I want to update chart data with ajax request or with a button. I couldn't update values. Anyone have an idea?
var graphDataArr = [{ label: 'My Graph', data: myDataArray, color: '#46F252', hoverable: false, clickable: false }];
new Ext.Window({
header : false,
layout : 'anchor',
height : 200,
width : 750,
baseCls : 'ext_panel_header_bar',
items : [ {
xtype : 'flot',
id : 'flotGraph',
cls : 'x-panel-body',
series : graphDataArr,
xaxis : {
min : xMin,
max : xMax
},
yaxis : {
min : yMin,
max : yMax
},
tooltip : false,
anchor : '98% 99%'
} ]
}).show();

Ext Flot API documentation says:
setData( Array Series ) : void
You can use this to reset the data used. Note that axis scaling, ticks, legend etc. will not be recomputed (use setupGrid() to do that). You'll probably want to call draw() afterwards.
You can use this function to speed up redrawing a plot if you know that the axes won't change. Put in the new data with setData(newdata) and call draw() afterwards, and you're good to go.
You could do the following in a button handler (where dataArray is your new data array):
var chart = Ext.getCmp('flotGraph');
chart.setData(dataArray);
chart.setupGrid();
chart.draw();

if you have send record from your web Application in Json/Proper format then you can simply create JavaScript that you can call on button /submit button.
function createCharts() {
var queryString = $('#mainForm').formSerialize();
var url_String = "runChartData.action" + '?'+queryString+'&selectedModule=Line';// URL to call ajax
$.ajax({
type: "post",
dataType: "json",
url: url_String,
async : true,
success: function(data){
chartData = data;
createChart(data); // the Method you have Created As I have created Bellow
}, error: function(data){
$('#chartDiv').empty(); //empty chart Div to recreate it.
}
});
}
createChart(var myDataArray){
$('#chartDiv').empty(); // reset to Create New Chart with new Data
var graphDataArr = [{ label: 'My Graph', data: myDataArray, color: '#46F252', hoverable: false, clickable: false }];
new Ext.Window({
header : false,
layout : 'anchor',
height : 200,
width : 750,
baseCls : 'ext_panel_header_bar',
items : [ {
xtype : 'flot',
id : 'flotGraph',
cls : 'x-panel-body',
series : graphDataArr,
xaxis : {
min : xMin,
max : xMax
},
yaxis : {
min : yMin,
max : yMax
},
tooltip : false,
anchor : '98% 99%'
} ]
}).show();
}

Related

Selecting row in child grid selects the row in parent grid with same row index

I have Implemented Nested Grid in Rowexpander Plugin.Now Issue is that when i am selecting any nth row of child grid then parent grid nth row also get selected . I think because both have same rowIndex.Even when i mouseover on the child grid row same mouseover effect display for parent also simultaneously.
Below is the code for Rowexpander
var expander = new Ext.ux.grid.RowExpander({
expandOnDblClick : false,
tpl : new Ext.Template('<div id="NestedGridRow-{id}"></div>'),
renderer: function(v, p, record) {
if (record.get('cmaStatus') == 'G') {
p.cellAttr = 'rowspan="2"';
return '<div class="x-grid3-row-expander"></div>';
}
},
});
expander.on('expand', expandedRow);
function expandedRow(obj, record, body, rowIndex){
//absId parameter for the http request to get the absence details.
//Use Id to give each grid a unique identifier. The Id is used in the row expander tpl.
//and in the grid.render("ID") method.
var row = "NestedGridRow-" + record.get("id");
var id2 = "mygrid-" +record.get("id");
sapid_para = record.get('sapid');
//Create the nested grid.
var gridX = new Ext.grid.GridPanel({
id:'nestedGrid',
store: storenested,
//stripeRows: true,
columns: [
{
header : "CMA Date",
width : 120,
sortable : true,
dataIndex : 'cmaDate',
},
{
header : "Source Model",
width : 120,
sortable : true,
dataIndex : 'sourceModel',
},
{
header : "Remarks",
width : 390,
sortable : true,
dataIndex : 'remarks',
}],
height: 120,
id: id2,
plugins : [editor],
renderTo: row,
stripeRows:true,
listeners: {
render: function(gridX) {
gridX.getView().el.select('.x-grid3-header').setStyle('display', 'none');
},
rowclick : function(grid,rowIndex,e) {
alert(rowIndex);
}
},
});
gridX.render(row);
//Ext.getCmp('grid_lineage').getStore().load({params:{start:0, limit:10}});
storenested.load({params:{start:0, limit:10}});
Please Help
I had the same issue. You will need to get a handle on the nested grid, and call this:
gridX.getEl().swallowEvent(['mouseover', 'mousedown', 'click', 'dblclick', 'onRowFocus']);

ExtJS XML Reader not loading data

My code is not showing any error, my php file is responding also(firebug reports that). But the grid is not showing any data. I was trying to get help from http://dev.sencha.com/deploy/ext-3.4.0/examples/feed-viewer/view.html but unable to understand it!. The idea is to provide a rss feed url to program, and it should fetch data from that url and then php file arranges it in a proper xml format just like the ExtJS example(from above link), upto this point, program is working fine, firebug says that response is an xml, but now, it not load.
Code:
var remoteProxy = new Ext.data.HttpProxy({
url : 'feed-proxy.php'
});
var store = new Ext.data.Store({
proxy : remoteProxy,
id : 'ourRemoteStore',
reader : new Ext.data.XmlReader({
record : 'item'
}, [{
name : 'title',
mapping : 'title'
}])
});
loadFeed = function(url) {
store.baseParams = {
feed : url
};
store.load();
console.log(store.getCount());
}
loadFeed('http://sports.yahoo.com/nba/rss.xml');
var mWIn = new Ext.Window({
title : 'My Window',
width : 500,
height : 400,
layout : 'fit',
items : [{
xtype : 'grid',
store : store,
id : 'myGrid',
loadMask : true,
columns : [{
id : 'title',
header : "Title",
dataIndex :'title',
sortable : true,
width : 420
}]
}]
}).show();
Ext.getCmp('myGrid').ownerCt.doLayout();
and php file code is :
<?php
// this is an example server-side proxy to load feeds
if(isset($_REQUEST['feed'])){
$feed = $_REQUEST['feed'];
if($feed != '' && strpos($feed, 'http') === 0){
header('Content-Type: text/xml');
$xml = file_get_contents($feed);
$xml = str_replace('<content:encoded>', '<content>', $xml);
$xml = str_replace('</content:encoded>', '</content>', $xml);
$xml = str_replace('</dc:creator>', '</author>', $xml);
echo str_replace('<dc:creator', '<author', $xml);
return;
}
}
?>

Sencha Touch Controller pushing a view

I'm trying to work out why when I push a view onto a Ext.Navigation.View control, the view I push renders, but the data I push with it doesn't. The view renders a very simple DataView control with some json data (name & surname).
It'll work if I create the view explicitly through "Ext.Create" (see commented out lines in controller), but I'm sure I've done this before where you can push "xtype" of the view and any relevant properties/data for the view. Am I right?
By the way, I've tested the json coming back from the form submission callback and everything is fine. It just seems to be the view doesn't want to render the data I send it as part of the "push". Here's my code. Am I missing something?:
View:
Ext.define('MyCo.Booking.view.PatientClinicSearchResults', {
extend : 'Ext.DataView',
xtype : 'DataViewPatientSearchResults',
itemTpl : '{Name}',
store : {
fields : ['Name'],
autoLoad : true
}
})
Controller :
Ext.define('MyCo.Booking.controller.Main', {
extend: 'Ext.app.Controller',
config: {
refs: {
navViewClinics : 'NavViewClinics',
formPanelClinicPatientSearch : 'FormPanelClinicPatientSearch'
},
control: {
'NavViewClinics list' : {
itemtap : 'ClinicUserSearch'
},
'FormPanelClinicPatientSearch button' : {
tap : 'ClinicPatientSearchResults'
}
}
},
ClinicUserSearch : function(list, index, element, record) {
this.getNavViewClinics().push({ xtype : 'FormPanelClinicPatientSearch' });
},
ClinicPatientSearchResults : function(button, e) {
var form = this.getFormPanelClinicPatientSearch();
var navClinics = this.getNavViewClinics();
form.submit({
success : function(form, result) {
// var view = Ext.create('MyCo.Booking.view.PatientClinicSearchResults', {
// title : 'Search Results',
// fullscreen: true,
// store: {
// fields: ['Name'],
// data : result.items
// },
// itemTpl: '<div>{Name}</div>'
// });
// navClinics.push(view);
navClinics.push({ xtype : "DataViewPatientSearchResults",
title : 'Test',
store : {
data : result.items
}
});
}
});
}
});
JSON received from form submission callback:
{
"success" : true,
"items" : [
{
"Name": "Jon",
"Surname": "Doe"
},
{
"Name": "Karl",
"Surname": "Doe"
}
]
}
Any help would be appreciated. Thank you.
Problem solved. I removed the store declaration from the view and it worked. Just need to reference the data via the itemTpl property.

search field in a dataview in extjs

Am trying to put a search field with respect to a data view. There is a toolbar on top of the data view, which consists of a text field. On entering some text in the field, i want to call a search functionality. As of now, i have got hold of the listener to the text field, but the listener is called immediately after the user starts typing something in the text field.
But, what am trying to do is to start the search functionality only when the user has entered at least 3 characters in the text field.How could i do this?
Code below
View
var DownloadsPanel = {
xtype : 'panel',
border : false,
title : LANG.BTDOWNLOADS,
items : [{
xtype : 'toolbar',
border : true,
baseCls : 'subMenu',
cls : 'effect1',
dock : 'top',
height : 25,
items : [{
xtype : 'textfield',
name : 'SearchDownload',
itemId : 'SearchDownload',
enableKeyEvents : true,
fieldLabel : LANG.DOWNLOADSF3,
allowBlank : true,
minLength : 3
}],
{
xtype : 'dataview',
border : false,
cls : 'catalogue',
autoScroll : true,
emptyText : 'No links to display',
selModel : {
deselectOnContainerClick : false
},
store : DownloadsStore,
overItemCls : 'courseView-over',
itemSelector : 'div.x-item',
tpl : DownloadsTpl,
id : 'cataloguedownloads'
}]
Controller:
init : function() {
this.control({
// reference to the text field in the view
'#SearchDownload' :{
change: this.SearchDownloads
}
});
SearchDownloads : function(){
console.log('Search functionality')
}
UPDATE 1: i was able to get hold of the listener after three characters have been entered using the below code:
Controller
'#SearchDownload' :{
keyup : this.handleonChange,
},
handleonChange : function(textfield, e, eOpts){
if(textfield.getValue().length > 3){
console.log('Three');
}
}
any guidance or examples on how to perform the search in the store of the data view would be appreciated.
A proper way would be to subscribe yourself to the change event of the field and check if the new value has at least 3 chars before proceeding.
'#SearchDownload' :{ change: this.handleonChange }
// othoer code
handleonChange : function(textfield, newValue, oldValue, eOpts ){
if(newValue.length >= 3){
console.log('Three');
}
}
Btw. I recommend you to use lowercase and '-' separated names for id's. In your case
itemId : 'search-download'
Edit apply the filter
To apply the filter I would use filter I guess you now the field you want to filter on? Lets pretend store is a variable within your controller than you may replace the console.log() with
this.store.filter('YourFieldName', newValue);
Second param can also be a regex using the value like in the example
this.store.filter('YourFieldName', new RegExp("/\"+newValue+"$/") );
For sure you can also use a Function
this.store.filter({filterFn: function(rec) { return rec.get("YourFieldName") > 10; }});
Thanks you so much sra for your answers. Here is what i did, based on your comments
filterDownloads : function(val, filterWh){
if(filterWh == 1){
var store = Ext.getStore('CatalogueDownloads');
store.clearFilter();
store.filterBy(function (r){
var retval = false;
var rv = r.get('title');
var re = new RegExp((val), 'gi');
retval = re.test(rv);
if(!retval){
var rv = r.get('shortD');
var re = new RegExp((val), 'gi');
retval = re.test(rv);
}
if(retval){
return true;
}
return retval;
})
}
}
i think there is an example of exactly what you are trying to achive .. http://docs.sencha.com/ext-js/4-0/#!/example/form/forum-search.html

the labelrenderer of the time axis in extjs

Note:
This is a cross post at:extjsForum
since I got no answer there,so I ask here.
Anyone who decide to answer this post can see the forum first to make sure if the question has been answer. :)
The following is my core code to make a Column chart to show the visitors and bytes of my website, however I found that I can not handle the label of the xAxis.
visitAndBytesStore = new Ext.data.JsonStore(
{
fields :
[
{
name : 'time',
type : 'string'
// dateFormat : 'Y-m-d H:i:s'
}, 'visits', 'bytes' ]
});
var visitAndBytesData =
[{"time" : "2010-09-17 16:24:06","visits" : "23","bytes" : "4545"},
{"time" : "2010-09-17 02:23:33","visits" : "3233","bytes" : "3232"},
{"time" : "2010-09-17 16:23:52","visits" : "456","bytes" : "3242342"},
{"time" : "2010-09-17 15:23:52","visits" : "6456","bytes" : "2314252"} ];
visitAndByteChart = new Ext.chart.ColumnChart(
{
store : visitAndBytesStore,
xField : 'time',
// xAxis : new Ext.chart.TimeAxis(
// {
// title : 'time',
// displayName : 'time',
// labelRenderer : function(dd)
// {
// // return dd.format("m-d")+"\n"+dd.format("H:i");
// return "";
// }
// }),
yAxis : new Ext.chart.NumericAxis(
{
displayName : 'Visits',
labelRenderer : Ext.util.Format.numberRenderer('0,0')
}),
series :
[
{
type : 'column',
displayName : 'Bytes',
yField : 'bytes',
style :
{
color : 0x99BBE8
}
},
{
type : 'line',
displayName : 'Visits',
yField : 'visits',
style :
{
mode : 'stretch',
color : 0x15428B
}
} ]
});
visitorAndBytesChartPanel = new Ext.Panel(
{
iconCls : 'chart',
title : '&nbsp',
frame : true,
renderTo : 'bytes',
autoWidth : true,
height : 300,
layout : 'fit',
items : visitAndByteChart
});
As shown above if I use the "string" format of the "time" field, I can not handle the format of the time label in the chart, their value are too long (2010-09-20 23:00:00 is too long),so they are displayed by Automaticly chosed.
This is the result:
http://awesomescreenshot.com/0e41vu0c0
I want all of them displayed.
So I set the "time" field to "date" (Just remove the comments in the above codes),
And now the last label in the chart can not displayed completely,so is the "dot" in the chart which trig the tip event.
This is the result:
http://awesomescreenshot.com/04c1vtq94
Is there any problems?
extraStyle: {
padding: 20
}
From the Forum

Resources