2012-01-17 64 views
0

我是新來的Flex,我一直在試圖找出如何使用下面的代碼爲Flex 4中軟硬度:需要幫助實現自定義組件的代碼虛線

http://riarange.wordpress.com/2010/10/29/how-to-create-a-dotted-line-or-dashed-line-in-flex-4/

創建虛線

我希望有人更好地瞭解Flex,可以簡單地提供一個完整的(最小)示例,該示例使用此代碼繪製虛線。我無法將這些部分拼湊在一起,我認爲作者假定了一些我缺乏的基本知識。如果我有一個工作的例子,我可以找出如何適應我的需求。

在此先感謝您的任何意見/幫助。如果有更好的虛線代碼,很想知道。

UPDATE:

我把自定義組件代碼到在COM目錄中的文件DottedLine.mxml。現在,我得到的是出現在<components:Group>行一個錯誤,指出:Could not resolve <components:Group> to a component implementation.

<mx:Application 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    xmlns:components="com.*" 
    minWidth="955" minHeight="600" xmlns:com="com.*"> 

<fx:Script><![CDATA[ 
    import mx.collections.ArrayCollection; 
    [Bindable] 
    public var expenses:ArrayCollection = new ArrayCollection([ 
    {Month:1, Profit:2000, Expenses:1500, Amount:450}, 
    {Month:2, Profit:1000, Expenses:200, Amount:600}, 
    {Month:2.05, Profit:1000, Expenses:500, Amount:300}, 
    {Month:2.1, Profit:1000, Expenses:500, Amount:450}, 
    {Month:2.15, Profit:1000, Expenses:200, Amount:600}, 
    {Month:2.2, Profit:1000, Expenses:500, Amount:300}, 
    {Month:2.25, Profit:1000, Expenses:500, Amount:450}, 
    {Month:2.3, Profit:1000, Expenses:200, Amount:600}, 
    {Month:2.35, Profit:1000, Expenses:500, Amount:300}, 
    {Month:2.4, Profit:1000, Expenses:500, Amount:450}, 
    {Month:2.45, Profit:1000, Expenses:200, Amount:600}, 
    {Month:2.5, Profit:1000, Expenses:500, Amount:300}, 
    {Month:2.55, Profit:1000, Expenses:500, Amount:450}, 
    {Month:2.6, Profit:1000, Expenses:200, Amount:600}, 
    {Month:2.65, Profit:1000, Expenses:500, Amount:300}, 
    {Month:2.7, Profit:1000, Expenses:500, Amount:450}, 
    {Month:2.75, Profit:1000, Expenses:200, Amount:600}, 
    {Month:2.8, Profit:1000, Expenses:500, Amount:300}, 
    {Month:2.85, Profit:1000, Expenses:500, Amount:450}, 
    {Month:2.9, Profit:1000, Expenses:200, Amount:600}, 
    {Month:6, Profit:1500, Expenses:500, Amount:300} 
    ]); 

]]></fx:Script> 

<mx:Panel title="Line Chart With Strokes"> 

    <mx:LineChart id="myChart" dataProvider="{expenses}" showDataTips="true" seriesFilters="{new Array}"> 
     <mx:horizontalAxis> 
      <mx:LinearAxis /> 
     </mx:horizontalAxis> 
     <mx:series> 
      <mx:LineSeries xField="Month" yField="Expenses" displayName="Expenses"> 
       <mx:lineStroke> 
        <mx:SolidColorStroke id="s1" color="0xBD171B" weight="4"/> 
       </mx:lineStroke> 
      </mx:LineSeries> 
      <mx:LineSeries xField="Month" yField="Amount" displayName="Amount"> 
       <components:Group> 
        <components:DottedLine width="500" height="2" dotColor="0xFFFFFF" dotWidth="3" dotAlpha="1" />  
       </components:Group> 
      </mx:LineSeries> 
     </mx:series> 
    </mx:LineChart> 
    <mx:Legend dataProvider="{myChart}" direction="horizontal"/> 
</mx:Panel> 

+0

這個例子看起來很完整,我不確定你錯過了什麼。 – JeffryHouser 2012-01-17 21:03:24

+1

好吧,我想這很好,那肯定是顯而易見的。我將編輯帖子以顯示我所做的努力來實現它。 – ggkmath 2012-01-17 21:29:05

+1

關於您遇到的錯誤,關於組件的問題意味着您沒有在您嘗試使用組件前綴的組件的根節點中定義的名稱空間。它應該被定義爲DottedLine類所在的包。如果DottedLine類基於它在項目中的位置具有正確的包名稱,那麼只需在 shaunhusain 2012-01-17 22:23:29

回答

1

我在Flex 3的做這些,但相信他們應該在的Flex 4都工作過,有」還有其他的例子比我擁有的和你發佈的更好,但這取決於你如何應用虛線。如果這沒有幫助讓我知道,我會盡力澄清: http://www.shaunhusain.com/TestDashedLines/index.html

http://www.shaunhusain.com/TestDashedLines/index2.html

http://www.shaunhusain.com/TestDashedLines/srcview/

我這裏有什麼是在一個項目中的兩個應用,第一頁是輸出使用SimpleDashedLine類,它基本上是用一個破折號繪製一個HRule。第二種是在其他對象圖形上繪製任意直線。

+0

謝謝肖恩,第一個鏈接有一些非常好的虛線功能。我的應用程序繪製科學的x,y數據,因此需要使用虛線繪製線條系列的方法。你的代碼是否適合這個? – ggkmath 2012-01-17 21:40:03

+0

嗨ggkmath,Yah DrawExternalDashedLine中的第二個版本應該做的伎倆。有了Flex 4,如果我的類導致了任何類型的表現,這可能需要使用Path(它並不是那麼複雜,所以我不認爲這會是一個問題,但我沒有嘗試過使用它除了在地圖上繪製約30件東西之外,取決於圖形繪製的複雜程度,也可能需要考慮一條線的末端與剩餘的破折號空間相關的位置) – shaunhusain 2012-01-17 21:46:59

+0

第一個版本雖然具有由於處理矩形旋轉是一種痛苦,因此更多選項僅用於繪製扁平線。 – shaunhusain 2012-01-17 21:47:33