How do I show/hide datatips on a chart with a seco

2019-07-27 19:43发布

问题:

I have a line chart with a column chart as a secondary series. When I roll over the line, the datatips appear. However, if I move the mouse to a spot where a column appears while still on the line, the data tip item appears for the line AND the column. How do I get it so that I only show datatips for the line but not the column?

<mx:AreaChart id="areachart" dataProvider="{data}" showDataTips="true" >
    <mx:series>

    <mx:AreaSeries id="areaSeries" xField="date" yField="volume" >
    </mx:AreaSeries>


    <mx:ColumnSeries id="secondSeries" xField="date" yField="name" >
    </mx:ColumnSeries>

    </mx:series>

</mx:AreaChart>

回答1:

Subclass AreaChart and override findDataPoints method to filter out the data points you don't want:

public class CustomAreaChart extends AreaChart
{
    public override function findDataPoints(x:Number, y:Number):Array
    {
        var originalDPs : Array = super.findDataPoints(x, y);
        var filteredDPs : Array = [];

        for each (var hd : HitData in originalDPs)
        {
            if (hd.chartItem.element is AreaSeries)
                filteredDPs.push(hd);
        }

        return filteredDPs;
    }
}

And then use this new class instead of AreaChart.



回答2:

Alternatively you can set the interactive property of the column to false:

   <mx:ColumnSeries id="secondSeries" xField="date" yField="name" interactive="false">
   </mx:ColumnSeries>

This will prevent the columns from responding to mouse input.