Witam
Mam taki problem z programem rysującym wykres ponieważ potrzebuje pobierać dane dla 2 różnych wykersow funkcji x y natomiast program pobiera mi tylko dane dla jednego wykresu oto kod programu proszę o pomoc.
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 ZedGraph;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
double x1;
double x2;
double y2;
double y1;
List<Coordinate> _coordinates = new List<Coordinate>();
public Form1()
{
InitializeComponent();
}
private void zedGraphControl1_Load(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
CreateGraph(zg1);
}
private void CreateGraph(ZedGraphControl zgc)
{
GraphPane myPane = zg1.GraphPane;
// Set the titles and axis labels
myPane.Title.Text = "Wykres";
myPane.XAxis.Title.Text = "X";
myPane.YAxis.Title.Text = "Y";
}
private void btnDraw_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(tbCoordinateX.Text) && !string.IsNullOrEmpty(tbCoordinateY.Text))
{
try
{
double x = double.Parse(tbCoordinateX.Text);
double y = double.Parse(tbCoordinateY.Text);
double x1 = double.Parse(tBx1.Text);
double y1 = double.Parse(tBy2.Text);
double x2 = double.Parse(tbCoordinateX.Text);
double y2 = double.Parse(tbCoordinateY.Text);
Coordinate coordinate = new Coordinate(x, y);
_coordinates.Add(coordinate);
tbCoordinateY.Text = "";
tbCoordinateX.Text = "";
AddPoint(coordinate);
}
catch
{
MessageBox.Show("Błędne współżędne. Obecny punkt nie zostanie dodany do wykresu.");
}
}
Clear();
DrawCoordinates();
}
private void btnSet_Click(object sender, EventArgs e)
{
try
{
double x1 = double.Parse(tBx1.Text);
double y1 = double.Parse(tBy2.Text);
double x = double.Parse(tbCoordinateX.Text);
double y = double.Parse(tbCoordinateY.Text);
Coordinate coordinate = new Coordinate(x, y);
_coordinates.Add(coordinate);
tbCoordinateY.Text = "";
tbCoordinateX.Text = "";
tBy2.Text = "";
tBx1.Text = "";
AddPoint(coordinate);
}
catch (Exception ex)
{
MessageBox.Show("Błędne współżędne.");
}
}
public void Clear()
{
}
public void DrawCoordinates()
{
GraphPane myPane = zg1.GraphPane;
//Make up some data points from the Sine function
PointPairList list = new PointPairList();
PointPairList list1 = new PointPairList();
PointPairList list2 = new PointPairList();
foreach (Coordinate item in _coordinates)
{
list.Add(item.X, item.Y);
list1.Add(item.x1, item.y1);
list2.Add(x2, y2);
}
Random random = new Random((int)DateTime.Now.Ticks);
int r= random.Next(0, 255);
int g= random.Next(0, 255);
int b= random.Next(0, 255);
//Generate a blue curve with circle symbols, and "My Curve 2" in the legend
LineItem myCurve = myPane.AddCurve("Wartość", list, Color.FromArgb(255,r,g,b),
SymbolType.Circle);
//Fill the area under the curve with a white-red gradient at 45 degrees
myCurve.Line.Fill = new Fill(Color.White);
// Make the symbols opaque by filling them with white
myCurve.Symbol.Fill = new Fill(Color.White);
//Fill the axis background with a color gradient
myPane.Chart.Fill = new Fill(Color.White);
// Fill the pane background with a color gradient
myPane.Fill = new Fill(Color.White);
zg1.Refresh();
// Calculate the Axis Scale Ranges
}
private void btnReset_Click(object sender, EventArgs e)
{
//Reset _coordinates and clear the graph
_coordinates = new List<Coordinate>();
zg1.GraphPane.CurveList.Clear();
zg1.Refresh();
tbCoordinateY.Text = "";
tbCoordinateX.Text = "";
lbPoints.Items.Clear();
}
private void AddPoint(Coordinate coordinate)
{
lbPoints.Items.Add(string.Format("Punkt {0} ma współrzędne: X = {1} Y = {2}", _coordinates.Count, coordinate.X, coordinate.Y));
}
private void tBx1_TextChanged(object sender, EventArgs e)
{
}
private void tBy2_TextChanged(object sender, EventArgs e)
{
}
}
}