2011-11-14 87 views
0

我有下面的ASP.NET動態圖表。我如何在x軸上爲每個日期放置圖表。目前有三條線沿y軸,2009年7月,2010年5月和2011年3月。我想爲每個日期分配一條線,因此您可以看到線上的每個點,並且還希望顯示每個點的日期放在圖表上。ASP.NET圖表列寬度

此外,似乎在圖表的開始和結尾填充並且沒有右邊框。我如何擺脫填充並獲得正確的邊框?

chart image

這裏是我的代碼:

前端:

<asp:Chart ID="chtReport" runat="server" Width="650px" Height="400px" ImageType="Jpeg"> 
    <Series> 
     <asp:Series Name="TotalLine" YValueType="Double" ChartType="Line" ChartArea="MainChartArea" /> 
     <asp:Series Name="GoalLine" YValueType="Double" ChartType="Line" ChartArea="MainChartArea" /> 
     <asp:Series Name="AverageLine" YValueType="Double" ChartType="Line" ChartArea="MainChartArea" /> 
     <asp:Series Name="TotalPoint" YValueType="Double" ChartType="Point" ChartArea="MainChartArea" /> 
     <asp:Series Name="GoalPoint" YValueType="Double" ChartType="Point" ChartArea="MainChartArea" /> 
     <asp:Series Name="AveragePoint" YValueType="Double" ChartType="Point" ChartArea="MainChartArea" /> 
    </Series> 
    <ChartAreas> 
     <asp:ChartArea Name="MainChartArea"> 
     </asp:ChartArea> 
    </ChartAreas> 
</asp:Chart> 

後端

protected void Page_Load(object sender, EventArgs e) 
{ 
    for (DateTime date = startDate; date <= ChartDetails.EndDate; date = date.AddMonths(1)) 
    { 
     dates.Add(date.ToString()); 
    } 

    grdChart.DataSource = dates; 
    grdChart.DataBind(); 

    chtReport.ChartAreas["MainChartArea"].AxisY.Minimum = 0; 
    chtReport.ChartAreas["MainChartArea"].AxisY.Maximum = 100; 
    chtReport.ChartAreas["MainChartArea"].AxisX.Title = "Date Range"; 
    chtReport.ChartAreas["MainChartArea"].AxisY.Title = "Percent"; 
} 


protected void grdChart_ItemDataBound(object sender, DataGridItemEventArgs e) 
{ 
    // Extra Code above... 

    chtReport.Series["TotalLine"].Points.AddXY(rowDate.ToString("MMM yyyy"), total); 
    chtReport.Series["GoalLine"].Points.AddXY(rowDate.ToString("MMM yyyy"), total); 
    chtReport.Series["AverageLine"].Points.AddXY(rowDate.ToString("MMM yyyy"), total); 

    chtReport.Series["TotalPoint"].Points.AddY(total); 
    chtReport.Series["GoalPoint"].Points.AddXY(rowDate.ToString("MMM yyyy"), total); 
    chtReport.Series["AveragePoint"].Points.AddXY(rowDate.ToString("MMM yyyy"), total); 
} 

預先感謝任何幫助。

回答

0

我添加下面的代碼行並我現在有網格線我一直在尋找。

chtReport.ChartAreas["MainChartArea"].AxisX.Interval = 1; 
0

嘗試style="padding:0"或使用外部的樣式表(CSS)來設置填充0

+0

我添加了一個沒有運氣的0填充樣式。除了填充問題之外,我還想在圖表上的每個日期上顯示一條線,以便上升Y軸。 – PsychoDUCK