开发者

Show YUI Pie Chart when no data returned in datasource

Unlike the other charts in YUI, such as the Line Chart, the pie-chart does not display an empty outline of the chart when no data is available. Instead nothing displays at all - just a blank space.

Is there a way to get the pie chart to display when no data is available?

I am constructing the chart to p开发者_开发百科ull the data from a datasource, polling at certain intervals.

this.chart = new YAHOO.widget.PieChart(id + '_c', this.datasource, {
        categoryField: categoryField,
        dataField: dataField,
        polling: interval * 1000,
        wmode: 'opaque',
        style: {
            background: { color: '#fdfdfd' },
            legend: { display: 'right' }
        }
    });


I found the way to do this is to override a method called onBeforeCallback on the live datasource. http://developer.yahoo.com/yui/docs/YAHOO.util.DataSourceBase.html#method_doBeforeCallback

Overridable method gives implementers access to the original full response and the parsed response (parsed against the given schema) before the data is added to the cache (if applicable) and then sent back to callback function. This is your chance to access the raw response and/or populate the parsed response with any custom data.

This allows you to change the data before sending it to the chart. If it is empty then I can add a dummy "No Activity" entry.

this.datasource.doBeforeCallback = function(oRequest, oFullResponse, oParsedResponse, oCallback) {
    if (!oParsedResponse.results || oParsedResponse.results.length < 1) {
       oParsedResponse.results = new Array({ "name": "No Activity", "count": "0" });
    }   
    return oParsedResponse;
 };
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜