示例#1
0
        protected override void ShowToolTip(object sender, MouseEventArgs e)
        {
            // Hide any existing tooltips
            HideToolTip(sender, e);

            ChartEventArgs chartEvent = this.GetChartEvent(sender, e);

            if (chartEvent == null || chartEvent.YValues.Length == 0)
            {
                return;
            }

            this._displayToolTips(sender, e, chartEvent.YValues, chartEvent.SeriesIndices);
        }
        protected override Size FillToolTipData(
            object sender,
            MouseEventArgs e,
            Path boundingRectElem,
            Path circleElem)
        {
            ChartEventArgs chartEvent = GetChartEvent(sender, e);

            int i = chartEvent.SeriesIndices[0];

            double yValue = chartEvent.YValues[0],
                   xValue = chartEvent.XValues[0];

            ChartModel model = Model;

            string[] seriesLabels = model.SeriesLabels;

            TextBlock textElem = ToolTip.Children[2] as TextBlock;

            textElem.Text = seriesLabels[i] + ": (" + xValue.ToString(Format) + ")    (" + yValue.ToString() + ")";

            double labelWidth  = textElem.ActualWidth;
            double labelHeight = textElem.ActualHeight;

            //We do not need the next label
            textElem = ToolTip.Children[3] as TextBlock;

            textElem.Text = "";

            double rectWidth = labelWidth + 2 * _TEXT_MARGIN;

            RectangleGeometry rg = boundingRectElem.Data as RectangleGeometry;
            Rect   rect          = rg.Rect;
            double rectHeight    = rect.Height;

            if (rectHeight > 2 * labelHeight)
            {
                rectHeight -= labelHeight;
            }
            rg.Rect = new Rect(rect.X, rect.Y, rectWidth, rectHeight);
            boundingRectElem.SetValue(Path.StrokeProperty, new SolidColorBrush(Model.SeriesColors[i]));

            EllipseGeometry eg = circleElem.Data as EllipseGeometry;

            eg.RadiusX = eg.RadiusY = 0;
            return(new Size(rectWidth, 2 * (labelHeight + _TEXT_MARGIN)));
        }
        protected override Size FillToolTipData(
            object sender,
            MouseEventArgs e,
            Path boundingRectElem,
            Path circleElem)
        {
            ChartEventArgs chartEvent = GetChartEvent(sender, e);

            CandleStickChartModel model = Model as CandleStickChartModel;

            var j = chartEvent.SeriesIndices[0];
            var i = chartEvent.YValueIndices[0];

            string[] groupLabels = model.GroupLabels,
            seriesLabels = model.SeriesLabels;

            double[][][] candleStickYValues = model.CandleStickYValues;

            Color[] seriesColors = model.SeriesColors;

            //top label
            TextBlock textElem = ToolTip.Children[2] as TextBlock;

            textElem.Text = seriesLabels[j];

            var labelWidth = textElem.ActualWidth;

            //Show the open-high-low-close values as comma separated
            StringBuilder sb = new StringBuilder();

            textElem = ToolTip.Children[3] as TextBlock;
            sb.Append(candleStickYValues[i][j][0].ToString(Format));
            sb.Append(", ");
            sb.Append(candleStickYValues[i][j][1].ToString(Format));
            sb.Append(", ");
            sb.Append(candleStickYValues[i][j][2].ToString(Format));
            sb.Append(", ");
            sb.Append(candleStickYValues[i][j][3].ToString(Format));
            textElem.Text = sb.ToString();

            var dataWidth = textElem.ActualWidth;

            // leave a  clearance on either end of the text
            double xMargin = _TEXT_MARGIN, dx = xMargin;

            if (labelWidth > dataWidth)
            {
                dx = (labelWidth - dataWidth) / 2 + xMargin;
            }

            textElem.SetValue(Canvas.LeftProperty, dx);

            var rectWidth = Math.Max(labelWidth, dataWidth) + 2 * xMargin;

            RectangleGeometry rg = boundingRectElem.Data as RectangleGeometry;
            Rect rect            = rg.Rect;

            rg.Rect = new Rect(0, 0, rectWidth, rect.Height);

            SolidColorBrush scb = new SolidColorBrush(seriesColors[j]);

            boundingRectElem.SetValue(Path.StrokeProperty, scb);
            circleElem.SetValue(Path.StrokeProperty, scb);

            return(new Size(rectWidth, 2 * (textElem.ActualHeight + _TEXT_MARGIN)));
        }