ASP.net chart control: hide all lines (axes, etc.) except data points

≯℡__Kan透↙ 提交于 2020-01-03 09:22:29

问题


I'm trying to generate sparklines for a dashboard using the Microsoft chart control on ASP.net. Sparklines generally have no axes or anything other than the data points showing.

I've succesfully turned off most of the lines but I'm stuck with one horizontal and one vertical line I can't figure out how to get rid of. Here's what I see:

Here's what I want:

Here's an excerpt of the code I'm using (minus the actual data):

Chart2.Width = 100;
Chart2.Height = 60;
Chart2.BorderlineWidth = 0;

var name = "Northeast Region";
ChartArea area = new ChartArea(name);
area.AxisX.LabelStyle.Enabled = false;
area.AxisY.LabelStyle.Enabled = false;
area.AxisX.MajorGrid.Enabled = false;
area.AxisY.MajorGrid.Enabled = false;
area.AxisY.MajorTickMark.Enabled = false;
area.AxisY.MinorTickMark.Enabled = false;
area.AxisX.MajorTickMark.Enabled = false;
area.AxisX.MinorTickMark.Enabled = false;
area.BorderWidth = 0;

Chart2.ChartAreas.Add(area);
Series s = new Series(area.Name);
s.ChartType = SeriesChartType.Line;
s.ChartArea = area.Name;
s.Color = System.Drawing.Color.Gray;
foreach (var row in Data)
{
    s.Points.AddXY(row.StartDate, row.Sales);
}
Chart2.Series.Add(s);

Any ideas what I'm doing wrong?


回答1:


Duh. I googled every possible combination of "hide" and "axis" and "line" but didn't Google "asp.net chart control sparklines" until after I posted this.

Answer is here: http://betterdashboards.wordpress.com/2010/02/21/how-to-create-a-sparkline-chart-in-asp-net/

I was missing setting the LineWidth property on the ChartArea:

area.AxisX.LineWidth = 0;
area.AxisY.LineWidth = 0;



回答2:


chart1.ChartAreas[0].AxisY.StripLines.Add(new StripLine()); 
chart1.ChartAreas[0].AxisY.StripLines[0].BackColor = Color.FromArgb(80, 252, 180, 65); 
chart1.ChartAreas[0].AxisY.StripLines[0].StripWidth = 40; 
chart1.ChartAreas[0].AxisY.StripLines[0].Interval = 10000; 
chart1.ChartAreas[0].AxisY.StripLines[0].IntervalOffset = 20;


来源:https://stackoverflow.com/questions/9626234/asp-net-chart-control-hide-all-lines-axes-etc-except-data-points

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!