带有空数据的饼图

发布于 2024-09-13 04:15:28 字数 85 浏览 7 评论 0原文

当 PieSeries 中的所有数据都等于 0 时,有什么方法可以强制 Flex 绘制空 PieChart。我现在得到的结果只是我的图表应该在的位置的空白。

Is there any way to force Flex to draw empty PieChart when all data in the PieSeries equals 0. The result I'm getting now is just a blank space in the place where my chart is supposed to be.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伊面 2024-09-20 04:15:28

可能不完全是您想要的,但下面的示例将为您提供一个空的橙色图表,其中有一个标记为空的图例条目(您可能希望保留完整的图例)。

替代文本

禁用标签和数据提示,当所有值设置为零时,运行一个函数来更改 dataProvider(下面的代码可能会有所帮助)

<?xml version="1.0"?>
<!-- charts/BasicPie.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
  <mx:Script><![CDATA[
     import mx.collections.ArrayCollection;
     [Bindable]
     public var expenses:ArrayCollection = new ArrayCollection([
        {Expense:"Taxes", Amount:1},
        {Expense:"Rent", Amount:2},
        {Expense:"Bills", Amount:3}
     ]);

     private function removeItems(event:Event):void{

        expenses.removeAll();
        expenses.addItem({Expense:"Empty", Amount:1});
        mySeries.setStyle("labelPosition", "false");
        myChart.showDataTips = false;

     }

  ]]></mx:Script>
  <mx:Panel title="Pie Chart" width="442" height="536">
     <mx:PieChart id="myChart" 
        dataProvider="{expenses}" 
        showDataTips="true"
        themeColor="#121212" alpha="1.0" width="100%" height="100%">
        <mx:series>
           <mx:PieSeries 
                id="mySeries"           
                field="Amount" 
                nameField="Expense" 
                labelPosition="callout"
           />
        </mx:series>
     </mx:PieChart>
     <mx:Button label="Remove items" click="removeItems(event)"/>
     <mx:Legend dataProvider="{myChart}"/>
  </mx:Panel>
</mx:Application>

Probably not exactly what you want, but the example below will give you an empty orange chart, with a single legend entry labeled Empty (you probably want to keep the full Legend).

alt text

Disable the labels and datatips, and when all values are set to zero, run a function to alter the dataProvider (the code below might be of some help)

<?xml version="1.0"?>
<!-- charts/BasicPie.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
  <mx:Script><![CDATA[
     import mx.collections.ArrayCollection;
     [Bindable]
     public var expenses:ArrayCollection = new ArrayCollection([
        {Expense:"Taxes", Amount:1},
        {Expense:"Rent", Amount:2},
        {Expense:"Bills", Amount:3}
     ]);

     private function removeItems(event:Event):void{

        expenses.removeAll();
        expenses.addItem({Expense:"Empty", Amount:1});
        mySeries.setStyle("labelPosition", "false");
        myChart.showDataTips = false;

     }

  ]]></mx:Script>
  <mx:Panel title="Pie Chart" width="442" height="536">
     <mx:PieChart id="myChart" 
        dataProvider="{expenses}" 
        showDataTips="true"
        themeColor="#121212" alpha="1.0" width="100%" height="100%">
        <mx:series>
           <mx:PieSeries 
                id="mySeries"           
                field="Amount" 
                nameField="Expense" 
                labelPosition="callout"
           />
        </mx:series>
     </mx:PieChart>
     <mx:Button label="Remove items" click="removeItems(event)"/>
     <mx:Legend dataProvider="{myChart}"/>
  </mx:Panel>
</mx:Application>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文