在asp.net中删除不必要的白色间距图表

时间:2015-09-21 20:34:26

标签: c# asp.net

早上好,我遇到了一个我无法解决的问题。我有一个页面,它有两个图表,但问题是这些图表很小,周围有很多空白区域。我尝试过设置Position和InnerPlotPosition属性,但更糟糕的是,它是图表上方的白板。

今天我的消息来源如下:

<div class="col-lg-12">
        <asp:Chart ID="grfStatus" runat="server" PaletteCustomColors="2, 65, 142; 255, 128, 0; Yellow; Red; Lime" Height="400px" Width="600px" BorderlineColor="Transparent">
            <Series>
                <asp:Series Name="Series1" ChartType="Pie">
                </asp:Series>
            </Series>
            <ChartAreas>
                <asp:ChartArea Name="ChartArea1" IsSameFontSizeForAllAxes="True" AlignmentOrientation="All">
                    <AxisY MaximumAutoSize="100">
                    </AxisY>
                    <AxisX MaximumAutoSize="100">
                    </AxisX>
                </asp:ChartArea>
            </ChartAreas>
            <Titles>
                <asp:Title Name="Title1" Text="Gráfico de Status" Font="Microsoft Sans Serif, 18pt" ForeColor="White">
                </asp:Title>
            </Titles>
            <Legends>
                <asp:Legend Alignment="Center" Docking="Bottom" IsTextAutoFit="False" Name="Default" LegendStyle="Row" />
            </Legends>
            <BorderSkin BackColor="0, 65, 139" BorderColor="Transparent" SkinStyle="FrameTitle8" />
        </asp:Chart>
    </div>
    <div class="col-lg-12">
        <asp:Chart ID="grfClientes" runat="server" PaletteCustomColors="2, 65, 142; 255, 128, 0; Yellow; Red; Lime" Height="400px" Width="600px">
            <Series>
                <asp:Series Name="Series1" ChartType="StackedBar" IsVisibleInLegend="False"></asp:Series>
            </Series>
            <ChartAreas>
                <asp:ChartArea Name="ChartArea1" IsSameFontSizeForAllAxes="True" AlignmentOrientation="All">
                    <AxisY MaximumAutoSize="100">
                    </AxisY>
                    <AxisX MaximumAutoSize="100">
                    </AxisX>
                </asp:ChartArea>
            </ChartAreas>
            <Titles>
                <asp:Title Name="Title1" Text="Gráfico de Evolução por Empresa" Font="Microsoft Sans Serif, 18pt" ForeColor="White">
                </asp:Title>
            </Titles>
            <Legends>
                <asp:Legend Alignment="Center" Docking="Bottom" IsTextAutoFit="False" Name="Default" LegendStyle="Row" />
            </Legends>
            <BorderSkin BackColor="0, 65, 139" SkinStyle="FrameTitle8" />
        </asp:Chart>
    </div>

C#

#region Populo o gráfico de pizza
        grfStatus.Series.Clear();
        //grfStatus.Legends.Clear();
        //grfStatus.Legends.Add(nomeLegenda);
        List<GraficoContagemStatus> relacaoStatus = visaoAgendamentoControle.ObterRelacaoGraficoContagemStatus(resultado);

        grfStatus.ChartAreas.Add(new ChartArea());
        grfStatus.Series.Add(new Series("Data"));
        grfStatus.Series["Data"].ChartType = SeriesChartType.Pie;
        //grfStatus.Series["Data"]["PieLabelStyle"] = "Outside";
        //grfStatus.Series["Data"]["PieLineColor"] = "Black";
        grfStatus.Series["Data"].Points.DataBindXY(relacaoStatus.Select(data => data.Status.ToString()).ToArray(),
                                                   relacaoStatus.Select(data => data.Contagem).ToArray());
        #endregion

        #region Populo o gráfico de barras (duplas)
        grfClientes.Series.Clear();
        //grfClientes.Legends.Clear();
        //grfClientes.Legends.Add(nomeLegenda);
        List<GraficoContagemClienteUz> relacaoClientes = visaoAgendamentoControle.ObterRelacaoGraficoContagemClienteUz(resultado);

        foreach (GraficoContagemClienteUz cliente in relacaoClientes)
        {
            grfClientes.ChartAreas.Add(new ChartArea());
            grfClientes.Series.Add(new Series(cliente.CLIENTE));
            grfClientes.Series[cliente.CLIENTE].ChartType = SeriesChartType.Bar;

            List<GraficoContagemClienteUz> rel = relacaoClientes.Where(x => x.CLIENTE == cliente.CLIENTE).ToList();

            grfClientes.Series[cliente.CLIENTE].Points.DataBindXY(rel.Select(data => data.CLIENTE.ToString()).ToArray(),
                                                                  rel.Select(data => data.QTD_UZ).ToArray());

        }
        #endregion

然后跟随生成的图像:

StreamWriter

enter image description here

1 个答案:

答案 0 :(得分:0)

问题是你在循环中重新添加了多个ChartArea。你已经通过你的标记完成了它。您的Series也是如此。仅使用循环将点添加到现有系列。这就是你的图表的样子:

enter image description here