0

In Flex 3, I have a line chart. My data provider for the line chart contains only one item.

When I draw the line chart, it plots the point. But it doesn't show the data tip.

It works if more than one item is present in dataprovider.

How can I make a data tip visible for line chart with dataprovider containing a single data item?

user723644
  • 31
  • 2

3 Answers3

0

There is a workaround to show the datatip. We need to add ROLL_OVER and ROLL_OUT mouse event listeners to the line series which has single datapoint.

<?xml version="1.0"?>
<!-- Simple example to demonstrate the LineChart and AreaChart controls. -->
<s: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">

    <fx:Script>
        <![CDATA[
            import mx.charts.HitData;
            import mx.charts.renderers.*;
            import mx.charts.series.items.LineSeriesItem;
            import mx.collections.ArrayCollection;

            [Bindable]
            private var expensesAC:ArrayCollection = new ArrayCollection( [
                { Month: "Jan", Profit: 2000 } ]);

            private function lineseriesRollOverHandler(event:MouseEvent):void
            {
                linechart.showAllDataTips = true;
            }

            private function lineserieRollOutHandler(event:MouseEvent):void
            {
                linechart.showAllDataTips = false;
            }

            private function dataTipFunction(hitData:HitData):String
            {
                if(hitData && hitData.item)
                {
                    var s:String = "";

                    if(hitData.element is LineSeries)
                    {

                        if(expensesAC.length <=1)
                            hitData.x = 56;

                        var lsi:LineSeriesItem = hitData.chartItem as LineSeriesItem;

                        if(lsi == null)
                            return "";

                        s += "<b>" + (hitData.element as LineSeries).displayName + "</b><br />";
                        s += lsi.xValue + "<br />";
                        s += lsi.yNumber;
                    }

                    return s;
                }

                return "";
            }

        ]]>
    </fx:Script>

    <fx:Declarations>
    </fx:Declarations>

    <mx:Panel width="100%" height="100%" layout="horizontal" title="Single point LineChart Example">

        <mx:LineChart id="linechart" width="45%" height="100%" dataProvider="{expensesAC}"
                      paddingLeft="5" paddingRight="5" showDataTips="true" dataTipFunction="dataTipFunction">

            <mx:horizontalAxis>
                <mx:CategoryAxis categoryField="Month"/>
            </mx:horizontalAxis>

            <mx:series>
                <mx:LineSeries displayName="Profit" form="curve"
                               itemRenderer="mx.charts.renderers.CircleItemRenderer"
                               legendMarkerRenderer="mx.charts.renderers.BoxItemRenderer"
                               rollOut="lineserieRollOutHandler(event)"
                               rollOver="lineseriesRollOverHandler(event)" yField="Profit"/>
            </mx:series>
        </mx:LineChart>

        <mx:Legend dataProvider="{linechart}"/>

    </mx:Panel>
</s:Application>
A J
  • 3,970
  • 14
  • 38
  • 53
0

Use PlotSeries instead of LineSeries when you only have one point. You will get a nice round point with its dataTip. How to do it exactly depends on how your data is built - if the data doesn't change after being assigned to the dataProvider, you can choose which type of series to use at that moment.

0

try the following code, in actionscript,

lineSeries.setStyle("itemRenderer", new ClassFactory(mx.charts.renderers.CircleItemRenderer));

in mxml,

<mx:LineSeries yField="Y" itemRenderer="mx.charts.renderers.CircleItemRenderer" xField="X" dataProvider="{lineDataProvider}">
Andrei Sfat
  • 8,440
  • 5
  • 49
  • 69
Kishore
  • 1
  • 1