Question about using Zedgraph [modified]
-
If this isn't the right place for this question please let me know. I was playing with one of the samples Multi Y Graph. I added a couple of varibles and execute it 4 different times via mouse click. The first time through all works as expected. The second time through the x and y axis work correctly but the 3rd and 4th do not. Can anyone point me in the right direction. Here is the code I am using...
public partial class Form1 : Form
{
private static int clickCount = 0;
//
private LineItem myCurve;
//
public Form1()
{
InitializeComponent();
}#region Graph Test // Call this method from the Form\_Load method, passing your ZedGraphControl instance public void CreateChart(ZedGraphControl zgc) { // Get a reference to the GraphPane GraphPane myPane = zgc.GraphPane; // Set the titles and axis labels myPane.Title.Text = "Demonstration of Multi Y Graph"; myPane.XAxis.Title.Text = "Time, s"; myPane.YAxis.Title.Text = "Velocity, m/s"; myPane.Y2Axis.Title.Text = "Acceleration, m/s2"; // Make up some data points based on the Sine function PointPairList vList = new PointPairList(); PointPairList aList = new PointPairList(); PointPairList dList = new PointPairList(); PointPairList eList = new PointPairList(); // Fabricate some data values for (int i = 0; i < 30; i++) { double time = (double)i; double acceleration = 2.0; double velocity = acceleration \* time; double distance = acceleration \* time \* time / 2.0; double energy = 100.0 \* velocity \* velocity / 2.0; aList.Add(time, acceleration); vList.Add(time, velocity); eList.Add(time, energy); dList.Add(time, distance); } if (clickCount == 1) { // Generate a red curve with diamond symbols, and "Velocity" in the legend LineItem myCurve = myPane.AddCurve("Velocity", vList, Color.Red, SymbolType.Diamond); // Fill the symbols with white myCurve.Symbol.Fill = new Fill(Color.White); // // Make the Y axis scale red myPane.YAxis.Sca
-
If this isn't the right place for this question please let me know. I was playing with one of the samples Multi Y Graph. I added a couple of varibles and execute it 4 different times via mouse click. The first time through all works as expected. The second time through the x and y axis work correctly but the 3rd and 4th do not. Can anyone point me in the right direction. Here is the code I am using...
public partial class Form1 : Form
{
private static int clickCount = 0;
//
private LineItem myCurve;
//
public Form1()
{
InitializeComponent();
}#region Graph Test // Call this method from the Form\_Load method, passing your ZedGraphControl instance public void CreateChart(ZedGraphControl zgc) { // Get a reference to the GraphPane GraphPane myPane = zgc.GraphPane; // Set the titles and axis labels myPane.Title.Text = "Demonstration of Multi Y Graph"; myPane.XAxis.Title.Text = "Time, s"; myPane.YAxis.Title.Text = "Velocity, m/s"; myPane.Y2Axis.Title.Text = "Acceleration, m/s2"; // Make up some data points based on the Sine function PointPairList vList = new PointPairList(); PointPairList aList = new PointPairList(); PointPairList dList = new PointPairList(); PointPairList eList = new PointPairList(); // Fabricate some data values for (int i = 0; i < 30; i++) { double time = (double)i; double acceleration = 2.0; double velocity = acceleration \* time; double distance = acceleration \* time \* time / 2.0; double energy = 100.0 \* velocity \* velocity / 2.0; aList.Add(time, acceleration); vList.Add(time, velocity); eList.Add(time, energy); dList.Add(time, distance); } if (clickCount == 1) { // Generate a red curve with diamond symbols, and "Velocity" in the legend LineItem myCurve = myPane.AddCurve("Velocity", vList, Color.Red, SymbolType.Diamond); // Fill the symbols with white myCurve.Symbol.Fill = new Fill(Color.White); // // Make the Y axis scale red myPane.YAxis.Sca
Read How to get an answer to your question[^] and with attention to #7. Following these guidelines will get better responses to your questions
I know the language. I've read a book. - _Madmatt
-
Read How to get an answer to your question[^] and with attention to #7. Following these guidelines will get better responses to your questions
I know the language. I've read a book. - _Madmatt
-
If this isn't the right place for this question please let me know. I was playing with one of the samples Multi Y Graph. I added a couple of varibles and execute it 4 different times via mouse click. The first time through all works as expected. The second time through the x and y axis work correctly but the 3rd and 4th do not. Can anyone point me in the right direction. Here is the code I am using...
public partial class Form1 : Form
{
private static int clickCount = 0;
//
private LineItem myCurve;
//
public Form1()
{
InitializeComponent();
}#region Graph Test // Call this method from the Form\_Load method, passing your ZedGraphControl instance public void CreateChart(ZedGraphControl zgc) { // Get a reference to the GraphPane GraphPane myPane = zgc.GraphPane; // Set the titles and axis labels myPane.Title.Text = "Demonstration of Multi Y Graph"; myPane.XAxis.Title.Text = "Time, s"; myPane.YAxis.Title.Text = "Velocity, m/s"; myPane.Y2Axis.Title.Text = "Acceleration, m/s2"; // Make up some data points based on the Sine function PointPairList vList = new PointPairList(); PointPairList aList = new PointPairList(); PointPairList dList = new PointPairList(); PointPairList eList = new PointPairList(); // Fabricate some data values for (int i = 0; i < 30; i++) { double time = (double)i; double acceleration = 2.0; double velocity = acceleration \* time; double distance = acceleration \* time \* time / 2.0; double energy = 100.0 \* velocity \* velocity / 2.0; aList.Add(time, acceleration); vList.Add(time, velocity); eList.Add(time, energy); dList.Add(time, distance); } if (clickCount == 1) { // Generate a red curve with diamond symbols, and "Velocity" in the legend LineItem myCurve = myPane.AddCurve("Velocity", vList, Color.Red, SymbolType.Diamond); // Fill the symbols with white myCurve.Symbol.Fill = new Fill(Color.White); // // Make the Y axis scale red myPane.YAxis.Sca
Try this in your button click event:
clickCount++;
if (clickCount > 4)
{
clickCount = 1;
zgc.GraphPane = new GraphPane();
}
CreateChart(zgc);some work with the pane size remains ...
-
Try this in your button click event:
clickCount++;
if (clickCount > 4)
{
clickCount = 1;
zgc.GraphPane = new GraphPane();
}
CreateChart(zgc);some work with the pane size remains ...
-
That did it...Thanks so much for your time rafone Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...
you´re welcome
-
thanks for the tip Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...
Did you find the solution for keeping the size of your GraphPane? If not, here is it: You need 2 floats
private float myHeight = 0;
private float myWidth = 0;and in your CreateChart, right after
GraphPane myPane = zgc.GraphPane;
you add:
if (myHeight == 0)
{
myWidth = myPane.Rect.Size.Width;
myHeight = myPane.Rect.Size.Height;
}
else
{
if (myPane.Rect.Size.Width < myWidth)
{
myPane.Rect = new RectangleF(0, 0, myWidth, myHeight);
}
} -
Did you find the solution for keeping the size of your GraphPane? If not, here is it: You need 2 floats
private float myHeight = 0;
private float myWidth = 0;and in your CreateChart, right after
GraphPane myPane = zgc.GraphPane;
you add:
if (myHeight == 0)
{
myWidth = myPane.Rect.Size.Width;
myHeight = myPane.Rect.Size.Height;
}
else
{
if (myPane.Rect.Size.Width < myWidth)
{
myPane.Rect = new RectangleF(0, 0, myWidth, myHeight);
}
}