nisc
nisc

Reputation: 4400

Ext JS 4.0 providing "unconventional" data to charts

I have a store which always contains a single record. Lets say the record looks like this:

{'good': 5, 'bad': 2, 'neutral': 3}

How would I render that as a Pie chart? Ext.js normally uses each record in a store as one point of the series. In my case, I have only one record and want it to be used as three points in the series.

Upvotes: 1

Views: 217

Answers (2)

Eric
Eric

Reputation: 6995

You have a couple options available to you. You can create a custom Ext.data.reader.Reader subclass that will convert your raw data into your formatted records, you can override the store's loadRawData method to convert JSON data into an Ext.data.ResultSet, or you can set a callback on the store's load method to get your record and manually convert it into your necessary record format. If you're going for reusability, I suggest making a Reader.

The Reader#readRecords method takes raw data and returns a ResultSet, which sounds exactly like what you're after. Take a look at the source from the Sencha docs website and you should be able to figure out where to go from there. Once you have your custom reader, pass it to your store's proxy during configuration and it should handle the work for you. If it doesn't automatically, you may need to call the store loadRawData, passing your JSON response.

Upvotes: 3

Mchl
Mchl

Reputation: 62359

Split it into three records. You can create your own instances of Record and fill them with data using your original record as source.

Upvotes: 3

Related Questions