Solved

C# Reference Chart Series on userform from another class

Posted on 2011-09-07
1
515 Views
Last Modified: 2012-05-12
Hi,

I'm just learning c# so believe this should not be to hard.

I have a chart on a form which when loaded a new Series called "PriceData" is created, please see the code below.

My problem is I have a class say called Class1 and I am trying to reference the Series called "PriceData" on the chart but cannot.

Any help would be great.

Thanks,

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
chartFXPair.ChartAreas.Clear();
chartFXPair.Series.Clear();
chartFXPair.Titles.Add("Blah");
ChartArea cArea = new ChartArea("Area");
cArea.AxisX.Minimum = 3;
cArea.AxisX.Maximum = 5;
cArea.AxisY.Minimum = 0;
cArea.AxisY.Maximum = 100;
chartFXPair.ChartAreas.Add(cArea);
Series seriesPrice = new Series("PriceData");
seriesPrice.ChartType = SeriesChartType.Line;
seriesPrice.ChartArea = "Area";
chartFXPair.Series.Add(seriesPrice);
seriesPrice.Points.AddXY(1, 50);
seriesPrice.Points.AddXY(2, 25);
seriesPrice.Points.AddXY(3, 70);
seriesPrice.Points.AddXY(4, 40);
}

Open in new window

0
Comment
Question by:mcs26
1 Comment
 
LVL 2

Accepted Solution

by:
AJRDev earned 500 total points
ID: 36498701
You are declaring the series inside a private method of the Form class, which is why you can't see it outside of that method.

Declare it as public at the class level and you should be able to reference it from any instance of your form.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now