Reputation: 1364
VB2010 using MS Chart Control: I think my question is basic but havent found out how to do it. When the form first loads the chart control shows nothing, not even a grid. When I load points into my series then the grid plus the points get displayed.
How can I display a template chart with just the gridlines so that the user can see that there is a chart that will be populated. I did try to add two bogus points to one of my series and then disable the series to not display the points but the Chart control doesn't see it as a reason to render a grid.
Thanks for any help.
Edit: Thanks to @baddack for giving me food for thought. Here is what i did:
On form load create a bogus series. This series will stay in the chart for the life of the app.
Dim srs As New Series 'create a new series
cht.Series.Add(srs) 'add series to chart
srs.ChartType = SeriesChartType.Point 'it will be a point chart with one point (or you can add several points to define your display envelope)
srs.Name = "bogus" 'name of our bogus series
srs.IsVisibleInLegend = False 'do not show the series in the legend
srs.Points.AddXY(25000, 1000) 'this will be a point in the upper-right corner of the envelope you want to display
srs.Points(0).MarkerColor = Color.Transparent 'no color for the marker
srs.Points(0).MarkerSize = 0 'no size for the marker
chtObstacles.Series("bogus").Enabled = True 'name of the bogus series
chtObstacles.Update() 'update the chart
then the first thing I do when I run my process is to clear all other series and enable the bogus series so that it can be used to size the "empty" grid.
cht.Series("srs1").Points.Clear()
cht.Series("srs2").Points.Clear()
cht.Series("bogus").Enabled = True
then run the process that provides the points for the chart:
if pointCount > 0 then
'turn off the series so it will not be used in the grid sizing
cht.Series("bogus").Enabled = False
'add points to the chart
'code to add points to MS Chart
endif
cht.ChartAreas("chaMain").RecalculateAxesScale() 'we must recalculate the axes scale to reset the mins/maxs
'resume updating UI
cht.Series.ResumeUpdates()
'force redraw of chart
cht.Update()
Upvotes: 0
Views: 67
Reputation: 2053
You can add an empty point to the chart. That will make the grids show up, but not display any points.
private void Form1_Load(object sender, EventArgs e)
{
chart1.Series.Clear();
SetChartAxisLines(chart1.ChartAreas[0]);
Series s = new Series();
chart1.Series.Add(s);
s.Points.Add();
s.Points[0].IsEmpty = true;
}
private void SetChartAxisLines(ChartArea ca)
{
//X-Axis
ca.AxisX.MajorGrid.LineColor = Color.DarkGray;
ca.AxisX.MajorGrid.LineDashStyle = ChartDashStyle.Dash;
ca.AxisX.MinorGrid.Enabled = true;
ca.AxisX.MinorGrid.LineColor = System.Drawing.Color.Silver;
ca.AxisX.MinorGrid.LineDashStyle = ChartDashStyle.Dot;
//Y-Axis
ca.AxisY.MajorGrid.LineColor = System.Drawing.Color.DarkGray;
ca.AxisY.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash;
ca.AxisY.MinorGrid.Enabled = true;
ca.AxisY.MinorGrid.LineColor = System.Drawing.Color.Silver;
ca.AxisY.MinorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot;
}
Upvotes: 1