コード例 #1
0
ファイル: LineChart.cs プロジェクト: Kybs0/Kybs0Charts
 private void SetXIntervalsAndLines(AxisSegmentMode axisYSegment)
 {
     if (axisYSegment == null)
     {
         var axisXModel = AxisX;
         if (axisXModel.Datas.Count > 0)
         {
             //使用数据添加X轴坐标
             int count = axisXModel.Datas.Count;
             for (int i = 0; i < count; i++)
             {
                 BottomGrid.ColumnDefinitions.Add(new ColumnDefinition());
             }
             int index = 0;
             foreach (var data in axisXModel.Datas)
             {
                 //底部
                 var textblock = new TextBlock();
                 textblock.Text                = data.Name;
                 textblock.Foreground          = axisXModel.Foreground;
                 textblock.VerticalAlignment   = VerticalAlignment.Top;
                 textblock.TextAlignment       = TextAlignment.Center;
                 textblock.HorizontalAlignment = HorizontalAlignment.Right;
                 textblock.Width               = data.LabelWidth;
                 textblock.Margin              = new Thickness(0, 5, -data.LabelWidth / 2, 0);
                 Grid.SetColumn(textblock, index);
                 BottomGrid.Children.Add(textblock);
                 index++;
             }
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// 设置Y轴方向间隔以及分割线
        /// </summary>
        protected void SetYIntervalsAndLines(AxisSegmentMode axisYSegmentMode)
        {
            if (axisYSegmentMode.SegmentItems.Count > 0)
            {
                int gridRows = axisYSegmentMode.SegmentItems.Count - 1;
                for (int i = 0; i < gridRows; i++)
                {
                    LeftGrid.RowDefinitions.Add(new RowDefinition());
                    MainGridYLines.RowDefinitions.Add(new RowDefinition());
                }
                int index = 0;
                foreach (var title in axisYSegmentMode.SegmentItems)
                {
                    var textblock = new TextBlock();
                    textblock.Text                = title.Name;
                    textblock.Foreground          = axisYSegmentMode.ForeGround;
                    textblock.HorizontalAlignment = HorizontalAlignment.Right;
                    textblock.Height              = axisYSegmentMode.LabelHeight;
                    if (index < gridRows)
                    {
                        textblock.VerticalAlignment = VerticalAlignment.Bottom;
                        textblock.Margin            = new Thickness(0, 0, 5, -axisYSegmentMode.LabelHeight / 2);//因为设置在行底部还不够,必须往下移
                        Grid.SetRow(textblock, gridRows - index - 1);
                    }
                    else
                    {
                        textblock.VerticalAlignment = VerticalAlignment.Top;
                        textblock.Margin            = new Thickness(0, -axisYSegmentMode.LabelHeight / 2, 5, 0);//最后一个,设置在顶部
                        Grid.SetRow(textblock, 0);
                    }
                    LeftGrid.Children.Add(textblock);

                    var border = new Border();
                    border.Height      = axisYSegmentMode.LineHeight;
                    border.BorderBrush = axisYSegmentMode.LineBrush;
                    double thickness = Convert.ToDouble(axisYSegmentMode.LineHeight) / 2;
                    border.BorderThickness = new Thickness(0, thickness, 0, thickness);
                    if (index < gridRows)
                    {
                        border.VerticalAlignment = VerticalAlignment.Bottom;
                        border.Margin            = new Thickness(0, 0, 0, -thickness);//因为设置在行底部还不够,必须往下移
                        Grid.SetRow(border, gridRows - index - 1);
                    }
                    else
                    {
                        border.VerticalAlignment = VerticalAlignment.Top;
                        border.Margin            = new Thickness(0, -thickness, 0, 0);//最后一个,设置在顶部
                        Grid.SetRow(border, 0);
                    }
                    MainGridYLines.Children.Add(border);
                    index++;
                }
            }
        }