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

2

6

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:

Actual

Here's what I want:

Desired

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?

Homonym answered 8/3, 2012 at 22:46 Comment(0)
H
6

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;
Homonym answered 8/3, 2012 at 23:1 Comment(0)
C
0
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;
Connett answered 26/4, 2013 at 5:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.