| Page 1 of 1 | [ 7 posts ] |
|
I have a basic pie chart showing (based on this example: http://developer.yahoo.com/yui/examples ... egend.html), and now I am trying to change the colors of the wedges in the chart. Based on what I can see in the documentation and in some other examples on the web, it looks like I need to set my colors via the "series" attribute, like so:
series: [{style:{colors:[0x953030, 0xFF8C40, 0xFFDB59, 0x8DC63F, 0xFFFFFF]}}] When I add this attribute to the collection passed as the last parameter to new YAHOO.widget.PieChart, my pie chart stops displaying. If I remove this attribute, then the chart displays again. I've looked my code up and down looking for a syntax error that might cause the Flash control to not display the chart, but I don't see anything wrong. Also, no Javascript errors are being reported by Firebug. I am using version 2.8.0r4. Is this the correct way to specify wedge colors for the pie chart? If not, what is the correct way? Thanks, Denis |
|
That is the correct way to change the colors. The code below successfully changes colors for the http://developer.yahoo.com/yui/examples ... egend.html example.
You should be able to use this a guide. If you are still having issues, please post a repro link or your full code. Tripp Code: var mychart = new YAHOO.widget.PieChart( "chart", opinionData, { dataField: "count", categoryField: "response", style: { padding: 20, legend: { display: "right", padding: 10, spacing: 5, font: { family: "Arial", size: 13 } } }, //only needed for flash player express install expressInstall: "assets/expressinstall.swf", series: [{style:{colors:[0x953030, 0xFF8C40, 0xFFDB59, 0x8DC63F, 0xFFFFFF]}}] }); |
|
Thanks,
I was able to take the pie chart example, set the colors the way you show, and get it to work in my browser. So, now I'm digging into what is different when trying to do the same thing within my web app. Once I nail down the difference, I'll post my findings here. Setting colors should have only taken a few minutes to do, has burned half a day so far... Denis |
|
I know what's causing the pie chart to not work when using custom colors, but I don't know why. Our web app uses both YUI and Prototype. If I remove the script tag that includes prototype.js, then the pie chart works. The odd thing is that the pie chart works with both YUI and Prototype when using the default colors.
Here is an example that demonstrates the problem: http://pastie.org/691241. It's essentially the example pie chart on the YUI web site, stripped down to pretty much the bare essentials. Note that to recreate, you'll need to grab prototype.js from http://www.prototypejs.org/download, and change the very first <script> tag in the example above to point at your copy of prototype.js. Thanks, Denis |
|
i have same question, if i use prototype.js link
just use page test : yui/examples/charts/charts-legend_clean.html <!-- 一旦引用了prototype.js chart series样式就掛了 --> <script type="text/javascript" src="../../build/prototype.js"></script> var mychart = new YAHOO.widget.PieChart( "chart", opinionData, { dataField: "count", categoryField: "response", series: [{style:{colors:[0x953030, 0xFF8C40, 0xFFDB59, 0x8DC63F, 0x00FFFF]}}], style: { padding: 20, legend: { display: "right", padding: 10, spacing: 5, font: { family: "Arial", size: 13 } } }, //only needed for flash player express install expressInstall: "assets/expressinstall.swf" }); no customer color style ; if remove prototype.js link , will show . HOW? Thanks. |
|
There is a bug in Prototype that is causing the custom wedge colors not to work. Please refer to the following YUI ticket for more details and best of all, how to work around this issue:
http://yuilibrary.com/projects/yui2/ticket/2528636 The quick answer is that you need to put the following in your page somewhere: <script type="text/javascript"> //<![CDATA[ // This hack is needed to work around an issue in Prototype with how it incorrectly implements the JSON.stringify // function (not according to the json spec). See here for more details: // http://yuilibrary.com/projects/yui2/ticket/2528561 delete Number.prototype.toJSON; delete Boolean.prototype.toJSON; delete String.prototype.toJSON; delete Array.prototype.toJSON; Hash.prototype.toJSON = function() { return this.toObject(); }; Object.toJSON = YAHOO.lang.JSON.stringify; //]] </script> |
|
Thanks, it work success.
谢谢! |
| Page 1 of 1 | [ 7 posts ] |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group