Solved

C# Reference Chart Series on userform from another class

Posted on 2011-09-07
1
523 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 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