示例#1
0
        public override void UpdateVisual()
        {
            var coordinateSystem = Drawing.CoordinateSystem;

            XAxisLabels.AdjustToNewRange(coordinateSystem.GetVisibleXPoints(), true);
            YAxisLabels.AdjustToNewRange(coordinateSystem.GetVisibleYPoints()
                                         .Where(y => y.Abs() > 0.001), false);
        }
    private void SetXAxis(OpenFlashChart.OpenFlashChart chart, List <string> labels)
    {
        XAxisLabels xLabels = new XAxisLabels();

        xLabels.Values   = labels;
        xLabels.Vertical = true;
        xLabels.Color    = "#000000";

        XAxis x = new XAxis();

        x.Colour     = "#000000";
        x.Labels     = xLabels;
        x.GridColour = "#ffffff";

        chart.X_Axis = x;
    }
示例#3
0
        /// <summary>
        /// Refresh the graph contents
        /// </summary>
        public void Refresh()
        {
            Children.Clear();

            double width  = ActualWidth;
            double height = ActualHeight;

            if (Data != null && Data.Count > 0 && height > 0 && width > 0)
            {
                // Calculate transform:
                Interval xRange, yRange;
                if (FlipXY)
                {
                    xRange = Data.ValueRange.Include(0);
                    yRange = Data.KeyRange.Include(0);
                }
                else
                {
                    yRange = Data.ValueRange.Include(0);
                    xRange = Data.KeyRange.Include(0);
                }

                if (xRange.IsValid && yRange.IsValid)
                {
                    //Extend range to include any axis label presets:
                    if (YAxisLabels != null)
                    {
                        yRange = yRange.Union(YAxisLabels.KeyRange());
                    }

                    if (XAxisLabels != null)
                    {
                        xRange = xRange.Union(XAxisLabels.KeyRange());
                    }


                    // Draw grid:

                    var xAxisLabels = XAxisLabels;
                    var yAxisLabels = YAxisLabels;
                    if (xAxisLabels == null)
                    {
                        xAxisLabels = GenerateAxisLabels(xRange, XAxisLabelSuffix);
                    }
                    if (yAxisLabels == null)
                    {
                        yAxisLabels = GenerateAxisLabels(yRange, YAxisLabelSuffix);
                    }


                    // Y-axis labels:
                    if (xAxisLabels != null)
                    {
                        foreach (KeyValuePair <double, string> kvp in xAxisLabels)
                        {
                            double x        = xRange.ParameterOf(kvp.Key) * width;
                            Line   gridLine = new Line();
                            gridLine.X1      = x;
                            gridLine.X2      = x;
                            gridLine.Y1      = 0;
                            gridLine.Y2      = height;
                            gridLine.Stroke  = Brushes.Black;
                            gridLine.Opacity = 0.25;
                            Children.Add(gridLine);

                            TextBlock tB = new TextBlock();
                            tB.Text          = kvp.Value;
                            tB.TextAlignment = TextAlignment.Right;
                            FormattedText fT = new FormattedText(kvp.Value, CultureInfo.CurrentCulture, tB.FlowDirection,
                                                                 new Typeface(tB.FontFamily, tB.FontStyle, tB.FontWeight, tB.FontStretch), tB.FontSize, tB.Foreground);

                            Children.Add(tB);
                            Canvas.SetLeft(tB, x - fT.Width / 2);
                            Canvas.SetTop(tB, (1 - yRange.ParameterOf(0)) * height + 5);
                        }
                    }

                    // Y-axis labels:
                    if (yAxisLabels != null)
                    {
                        foreach (KeyValuePair <double, string> kvp in yAxisLabels)
                        {
                            double y        = (1 - yRange.ParameterOf(kvp.Key)) * height;
                            Line   gridLine = new Line();
                            gridLine.X1      = 0;
                            gridLine.X2      = width;
                            gridLine.Y1      = y;
                            gridLine.Y2      = y;
                            gridLine.Stroke  = Brushes.Black;
                            gridLine.Opacity = 0.25;
                            Children.Add(gridLine);

                            TextBlock tB = new TextBlock();
                            tB.Text          = kvp.Value;
                            tB.TextAlignment = TextAlignment.Right;
                            Children.Add(tB);
                            Canvas.SetRight(tB, (1 - xRange.ParameterOf(0)) * width + 5);
                            Canvas.SetTop(tB, y - tB.FontSize / 2);
                        }
                    }


                    // X-axis:
                    Line xAxis = new Line();
                    xAxis.X1              = 0;
                    xAxis.X2              = width;
                    xAxis.Y1              = (1 - yRange.ParameterOf(0)) * height;
                    xAxis.Y2              = xAxis.Y1;
                    xAxis.Stroke          = Brushes.Black;
                    xAxis.StrokeThickness = 2.0;
                    Children.Add(xAxis);

                    // Y-axis:
                    Line yAxis = new Line();
                    yAxis.X1              = xRange.ParameterOf(0) * width;
                    yAxis.X2              = yAxis.X1;
                    yAxis.Y1              = 0;
                    yAxis.Y2              = height;
                    yAxis.Stroke          = Brushes.Black;
                    yAxis.StrokeThickness = 2.0;
                    Children.Add(yAxis);



                    // Draw graph lines:
                    for (int i = 0; i < Data.Count; i++)
                    {
                        GraphLineData data = Data[i];
                        Colour        col  = Colour.FromHSV(i * 360.0 / Data.Count, 255, 255);

                        Polyline pLine = new Polyline();
                        pLine.Stroke = new SolidColorBrush(ToWPF.Convert(col));
                        //pLine.StrokeThickness = 1.0;
                        pLine.ToolTip = data.Name;
                        ToolTipService.SetInitialShowDelay(pLine, 0);
                        ToolTipService.SetShowDuration(pLine, 60000);

                        //Generate points:
                        PointCollection points = new PointCollection();
                        var             graph  = data.Data;
                        foreach (KeyValuePair <double, Interval> kvp in graph)
                        {
                            points.Add(ToPoint(kvp.Key, kvp.Value.End, xRange, yRange));
                        }
                        if (graph.IsEnvelope)
                        {
                            foreach (KeyValuePair <double, Interval> kvp in graph.Reverse())
                            {
                                points.Add(ToPoint(kvp.Key, kvp.Value.Start, xRange, yRange));
                            }
                        }

                        pLine.Points = points;

                        Children.Add(pLine);
                    }
                }
            }
        }
示例#4
0
 public override void OnRemovingFromCanvas(Canvas leavingContainer)
 {
     XAxisLabels.OnRemovingFromCanvas(leavingContainer);
     YAxisLabels.OnRemovingFromCanvas(leavingContainer);
 }
示例#5
0
 public override void OnAddingToCanvas(Canvas newContainer)
 {
     XAxisLabels.OnAddingToCanvas(newContainer);
     YAxisLabels.OnAddingToCanvas(newContainer);
 }
示例#6
0
        OpenFlashChart.OpenFlashChart BuildChart()
        {
            OpenFlashChart.OpenFlashChart chart = new OpenFlashChart.OpenFlashChart();
            List <double> data1 = new List <double>();

            int maxDot = 0;

            for (double i = 0; i < Days; i++)
            {
                //data1.Add(rand.Next(30));
                DateTime startTime = BeginDate.AddDays(i);
                DateTime endTime   = startTime.AddDays(1);
                int      pv        = PageVisitorHelper.GetVisitorCountByTime(startTime, endTime);
                if (pv > maxDot)
                {
                    maxDot = pv;
                }
                data1.Add(pv);
            }

            OpenFlashChart.Area area = new Area();
            area.Values   = data1;
            area.HaloSize = 0;
            area.Width    = 4;
            //area.DotSize = 2;
            area.FontSize         = 12;
            area.DotStyleType.Tip = "#x_label#<br>访客数:#val#";
            //area.DotStyleType.Type = DotType.ANCHOR;
            area.DotStyleType.Type   = DotType.DOT;
            area.DotStyleType.Colour = "#0077CC";

            area.Tooltip   = "提示:#val#";
            area.Colour    = "#0077CC";
            area.FillColor = "#E6F2FA";
            area.FillAlpha = .5;
            Animation animation = new Animation();

            animation.Cascade    = 1;
            animation.Delay      = 0.5;
            animation.Type       = "pop-up";
            area.OnShowAnimation = animation;
            chart.AddElement(area);
            chart.Y_Legend                = new Legend("");
            chart.Title                   = new Title("");
            chart.Tooltip                 = new ToolTip("#x_label#<br>访客数:#val#");
            chart.Tooltip.MouseStyle      = ToolTipStyle.FOLLOW;
            chart.Tooltip.Shadow          = false;
            chart.Tooltip.BackgroundColor = "#ffffff";
            chart.Tooltip.Rounded         = 3;
            chart.Tooltip.Stroke          = 2;
            chart.Tooltip.Colour          = "#000000";
            chart.Tooltip.BodyStyle       = "color: #000000; font-weight: normal; font-size: 11;";

            maxDot = (int)(maxDot * 1.3);
            chart.Y_Axis.SetRange(0, maxDot, maxDot / 3);
            chart.X_Axis.GridColour = "#eeeeee";
            chart.Y_Axis.GridColour = "#eeeeee";
            chart.X_Axis.Colour     = "#333333";
            chart.Y_Axis.Colour     = "#333333";
            chart.Bgcolor           = "#fbfbfb";

            List <string> data2 = new List <string>();

            for (int i = 0; i < Days; i++)
            {
                data2.Add(BeginDate.AddDays(i).ToString("yyyy年MM月dd日"));
            }

            XAxis x = new XAxis();

            x.GridColour = "#eeeeee";
            x.Stroke     = 1;
            x.Steps      = Steps;
            XAxisLabels xlabels = new XAxisLabels();

            xlabels.Steps    = Steps;
            xlabels.Vertical = false;
            xlabels.SetLabels(data2);
            x.Labels     = xlabels;
            chart.X_Axis = x;

            chart.Tooltip            = new ToolTip("全局提示:#val#");
            chart.Tooltip.Shadow     = true;
            chart.Tooltip.Colour     = "#e43456";
            chart.Tooltip.MouseStyle = ToolTipStyle.CLOSEST;
            return(chart);
        }