コード例 #1
0
        private void DrawLabel(LabelModel labelModel, ChartPlotInfo info, LabelAlign align = LabelAlign.Left)
        {
            switch (align)
            {
                case LabelAlign.Left:
                    break;
                case LabelAlign.Center:
                    labelModel.XPix -= labelModel.Text.Length * 4;
                    break;
                case LabelAlign.Right:
                    break;
                default:
                    break;
            }

            var textBlock = new TextBlock();
            textBlock.Text = labelModel.Text;

            RenderElement(textBlock, labelModel.XPix, labelModel.YPix);
        }
コード例 #2
0
        private void DrawGrid(ChartPlotInfo info)
        {
            var frameBrush = Brushes.SteelBlue;
            var gridBrush = Brushes.LightSteelBlue;

            //Grid
            for (DateTime x = info.MinX; x < info.MaxX; x += info.XStep)
            {
                if (x > info.MinX)
                {
                    DrawLine(x, 0, x, info.PhysHeight, info, gridBrush, true);
                }
                var labelModel = new LabelModel(info)
                {
                    Text = string.Format("{0:dd MMM yyyy}", x),
                    XPhys = x,
                    YPix = info.MaxHeight + ARGUMENT_LABEL_VERTICAL_SHIFT + info.HeaderHeight
                };

                DrawLabel(labelModel, info);
            }

            for (var y = info.MinY; y <= info.MaxY; y += info.YStep)
            {
                DrawLine(0, y, info.Width, y, info, gridBrush, true);

                var labelModel = new LabelModel(info)
                {
                    Text = string.Format("{0:F1}", y),
                    XPix = VALUE_LABEL_HORIZONTAL_SHIFT,
                    YPhys = y
                };
                DrawLabel(labelModel, info);
            }

            //Frame
            //left
            DrawLine(0, 0, 0, info.MaxY, info, frameBrush);
            //right
            DrawLine(info.Width, 0, info.Width, info.MaxY, info, frameBrush);
            //bottom
            DrawLine(0, info.MaxY, info.Width, info.MaxY, info, frameBrush);
            //top
            DrawLine(0, 0, info.Width, 0, info, frameBrush);
        }