2

我正在创建几个图表,但我无法弄清楚为什么图表的左侧和右侧有这么多空白空间。我有一个 Winforms 图表、ChartArea 和 Series,并且图表的左侧和右侧总是有一英寸好,看起来像是浪费了空间。我需要更改什么设置来减小这个空白空间的大小?我在这篇文章中包含了带有空白区域的图表的屏幕截图以及我用来创建它的代码。提前致谢。

在此处输入图像描述

        if (listBoxCharts.SelectedItems.Count == 1)
        {
            switch (listBoxCharts.SelectedItem.ToString().Trim())
            {
                case "Incomplete Work Orders By Status":
                    ChartArea chartArea = new ChartArea();
                    Series series = new Series();
                    Title title = new Title();

                    chartArea.Area3DStyle.Enable3D = true;
                    chartArea.Area3DStyle.LightStyle = LightStyle.Realistic;
                    chartArea.Area3DStyle.Rotation = 10;
                    chartArea.Area3DStyle.WallWidth = 3;
                    chartArea.BorderColor = Color.Transparent;
                    chartArea.Name = "IncompleteWorkOrdersByStatus_ChartArea";

                    // Fix this hack
                    ChartContainer.ChartAreas.Clear();
                    this.ChartContainer.ChartAreas.Add(chartArea);
                    this.ChartContainer.Dock = DockStyle.Fill;
                    this.ChartContainer.Location = new Point(2, 21);
                    this.ChartContainer.Name = "Charts";
                    this.ChartContainer.PaletteCustomColors = new Color[] { Color.LemonChiffon };

                    series.ChartArea = "IncompleteWorkOrdersByStatus_ChartArea";
                    series.ChartType = SeriesChartType.StackedColumn;
                    series.CustomProperties = "DrawingStyle=Cylinder";
                    series.EmptyPointStyle.BorderDashStyle = ChartDashStyle.NotSet;
                    series.IsXValueIndexed = true;
                    series.Name = "IncompleteWorkOrdersByStatus_Series";

                    List<WorkOrder> incompleteWorkOrders = woDao.getIncompleteWorkOrders();

                    var uniqueStatuses = (
                        from statuses in incompleteWorkOrders
                        select statuses.fkOrderStatus).Distinct().ToList();

                    int xVal = 1;
                    foreach (var status in uniqueStatuses)
                    {
                        var count = (
                            from wo in incompleteWorkOrders
                            where wo.fkOrderStatus == status
                            select wo).Count();

                        DataPoint dPoint = new DataPoint(xVal, count);
                        if (status == null)
                        {
                            dPoint.AxisLabel = "No Status";
                        }
                        else
                        {
                            dPoint.AxisLabel = status.codedesc;
                        }

                        dPoint.ToolTip = count + " " + dPoint.AxisLabel;

                        series.Points.Add(dPoint);

                        xVal++;
                    }

                    this.ChartContainer.Series.Clear();
                    this.ChartContainer.Series.Add(series);

                    title.DockedToChartArea = "IncompleteWorkOrdersByStatus_ChartArea";
                    title.IsDockedInsideChartArea = false;
                    title.Name = "IncompleteWorkOrdersByStatus_Title";
                    title.Text = "Incomplete Work Orders By Status";

                    this.ChartContainer.Titles.Clear();
                    this.ChartContainer.Titles.Add(title);
                    break;

                default:
                    break;
            }
        }
4

1 回答 1

3

尝试使用 InnerPlotPosition 设置:

chart1.ChartAreas[0].InnerPlotPosition.X = 0;
于 2012-10-20T04:17:56.590 回答