为什么MSChart不填写整个图表区域?

时间:2012-10-20 02:56:41

标签: c# winforms charts mschart

我正在制作一些图表,我无法弄清楚为什么图表的左侧和右侧有太多的空白区域。我有一个Winforms Chart,ChartArea和Series,在图表的左侧和右侧总是有一个很好的英寸,看起来像是浪费了空间。我需要更改什么设置才能减小这个空白区域的大小?我已经在这个帖子中包含了空白空间的图表截图以及我用来创建它的代码。提前谢谢。

enter image description here

        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;
            }
        }

1 个答案:

答案 0 :(得分:2)

尝试使用InnerPlotPosition设置:

chart1.ChartAreas[0].InnerPlotPosition.X = 0;