Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.NET 3.5 Chart won't display data

Status
Not open for further replies.

jebenson

Technical User
Feb 4, 2002
2,956
US
Hello all,

I am trying to learn the .NET 3.5 Chart control, and I'm having some problems. As I said in the title, the data won't display on the chart. I generate a DataTable with data as follows:

Month Fund7206 Fund7208 Fund7624 Fund 7642
1/2010 7245.05 2163993.18 19144.53 0
2/2010 1023294 2051675.46 156709.35 386550.15
3/2010 152365.32 622951.55 21541.41 1864914.85
4/2010 -4174.79 365628.92 6753.26 2452248.74
5/2010 -90.43 310245.35 18284.98 1717070.72
6/2010 0 75279.6 131267.38 1917728.54
7/2010 72.6 48303.17 11692.61 2248545.48
8/2010 676993.72 729642.44 -300503.7 631067.89

Then I create a chart:

Dim Chart1 As New Charting.Chart

Me.Controls.Add(Chart1)

Chart1.Top = 5
Chart1.Left = 5
Chart1.Width = 1000
Chart1.Height = 600

I assign the view of this table to the chart's DataSource like so:

Chart1.DataBindTable(dtAgy.AsDataView, "Month")

I get no errors, but the chart is blank. As in, completely white, not even the axes, grids or anything appear.


Now, if I add the chart to the form at design-time, then do the data assignment, it chart populates and shows the data, grids, etc.

I really need this to be dynamic though. My users could choose anything from 1 to 100+ charts to be generated, and the size of the list of charting candidates fluctuates. So I can't just add 100 chart controls at design-time and use them as needed. I need to be able to add charts dynamically, at run-time.

So, has anybody ever used this control and run into this issue? Know how to fix/workaround it?


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 

Ok, for future reference in case anybody else encounters this problem, here's the solution.

Creating the Chart control is just the first step. After creating the Chart control and binding data, add a ChartArea to it:

Code:
Chart1.DataBindTable(dtAgy.DefaultView, "Month")

'Add a ChartArea to the chart
Chart1.ChartAreas.Add("Area1")

'Add a legend to the chart
Chart1.Legends.Add("Legend1")

Next you need to assign each of the series in the chart to the ChartArea. You can also set the ChartType for each series (i.e., line, bar, etc.):

Code:
For Each s As Charting.Series In chart2.Series
    'make this series a line
    s.ChartType = Charting.SeriesChartType.Line

    'assign series to ChartArea
    s.ChartArea = "Area1"
Next

None of the tutorials at M$ mention this; they all just place a control on the form and go. I found this info about 12 posts deep in a thread about the .NET 3.5 Chart control.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top