jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Correct way to work with dataAdapter & charts
This topic contains 1 reply, has 2 voices, and was last updated by Peter Stoev 12 years, 6 months ago.
-
Author
-
Hi there
I have a webservice method that gives back a data array that I’d like to show in a chart. So when the user clicks a button I fire something like:
...get resultArray data... var dataSourceStatsChart = { datatype: "array", localdata: resultArray }; var dataAdapterStatsChart = new $.jqx.dataAdapter(dataSourceStatsChart); $("statsChart").jqxChart({ source: dataAdapterStatsChart, enableAnimations: true, enableAnimations: false, showLegend: true, borderColor: '#e3e3e3', background: '#e3e3e3', categoryAxis: { dataField: 'T0', formatFunction: function (value) { return value.substr(0,2).replace(/^0+/, ''); }, toolTipFormatFunction: function (value) { return value; }, showTickMarks: true, tickMarksInterval: 1, showGridLines: false, unitInterval: 1, axisSize: 'auto' }, colorScheme: 'scheme04', seriesGroups: [{ type: 'stackedcolumn', columnsGapPercent: 100, valueAxis: { minValue: 0, maxValue: myMaxValue, unitInterval: myUnitInterval, displayValueAxis: true, showGridLines: false, axisSize: 'auto', }, series: [ {dataField: 'T1', displayText: 'Company'}, {dataField: 'T2', displayText: 'City'}, {dataField: 'T3', displayText: 'Country'} ] }] });
Do I need to always create a new dataAdapter and initialize the chart when the user clicks the button, or do I basically initialize everything once (for example in $(document).ready(function () {}) and then only assign somehow the source property of the chart when the user clicks the button!?
Thanks & cheers,
PeterHi Peter,
With jqxChart, you just need to set its source property to point to an instance of jqxDataAdapter to update the Chart’s data. If you already have an instance of jqxDataAdapter, you can refresh the jqxDataAdapter’s data by calling its dataBind method. However, it is OK to create a new instance of jqxDataAdapter and set the Chart’s source property to point to it.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.