我在下面有以下ASP.NET动态图表。对于x轴上的每个日期,我如何在图表中放置线条。目前在y轴上有3条线,分别是2009年7月,2010年5月和2011年3月。我希望每个日期都有一条线,所以你可以看到线上的每个点,我还想显示每个点的日期。放在图表上。
此外,似乎在图表的开头和结尾填充,没有右边框。如何摆脱填充并获得正确的边框?
这是我的代码:
前端:
<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 :(得分:0)
尝试style="padding:0"
或使用外部样式表(CSS)设置填充0
答案 1 :(得分:0)
我添加了以下代码行,现在我有了我正在寻找的网格线。
chtReport.ChartAreas["MainChartArea"].AxisX.Interval = 1;