Skip to content

Instantly share code, notes, and snippets.

@MyCADDev
Created September 3, 2011 03:39
Show Gist options
  • Save MyCADDev/1190511 to your computer and use it in GitHub Desktop.
Save MyCADDev/1190511 to your computer and use it in GitHub Desktop.
Rendering a Chart with a Netzke component
{
initComponent: function(params)
{
// Define the model
Ext.define(this.id, {
extend: 'Ext.data.Model',
idProperty: this.pri, // Primary key
fields: [{
name: 'month',
type: 'int'
},
{
name: 'comission',
type: 'float'
}]
});
var store = new Ext.data.Store({
model: this.id,
proxy: {
type: 'direct',
directFn: Netzke.providers[this.id].get_data,
reader: {
type: 'json',
root: 'sales'
}
},
autoLoad: true
});
this.store = store;
Netzke.classes.MyChart.superclass.initComponent.call(this);
}
}
class MyChart < Netzke::Base
# Our JS class will be inherited from Ext.chart.Chart
js_base_class "Ext.chart.Chart"
js_mixin :my_chart
include Netzke::Basepack::DataAccessor
js_properties :title => 'Simple Chart', :width => 800, :height => 600
def js_config #:nodoc:
super.merge({
:animate => true,
:model => config[:model],
:pri => data_class.primary_key,
:axes => [{
:type => 'Numeric',
:position => 'left',
:fields => ['comission'],
:title => 'Sample Values',
:grid => true,
:minimum => 0
}, {
:type => 'Category',
:position => 'bottom',
:fields => ['month'],
:title => 'Sample Metrics'
}],
:series => [{
:type => 'column',
:axis => 'left',
:gutter => 80,
:stacked => true,
:xField => 'month',
:yField => 'comission'
}]
})
end
endpoint :get_data do |params|
sales = data_class.all()
sales.map do |s|
{:month => s.month, :comission => s.comission}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment