I have a data set , and hypothesis function, but cant combine them into one, any advices?
i used
ScatterplotBox.Show("Training data",x,y);
ScatterplotBox.Show("Training data",area.ToArray(),h);
You can use ScatterplotView instead, but you're also going to need a Form to hold it. Take a look:
static void Main(string[] args)
{
Random r = new Random();
int max = 15;
double[] x = new double[max];
double[] y1 = new double[max];
double[] y2 = new double[max];
for (int i = 0; i < max; i++)
{
x[i] = i;
y1[i] = r.Next(0, 50);
y2[i] = r.Next(50, 100);
}
ScatterplotView spv = new ScatterplotView();
spv.Dock = DockStyle.Fill;
spv.LinesVisible = true;
spv.Graph.GraphPane.AddCurve("Curve 1", x, y1, Color.Red, SymbolType.Circle);
spv.Graph.GraphPane.AddCurve("Curve 2", x, y2, Color.Blue, SymbolType.Diamond);
spv.Graph.GraphPane.AxisChange();
Form f1 = new Form();
f1.Width = 600;
f1.Height = 400;
f1.Controls.Add(spv);
f1.ShowDialog();
Console.ReadLine();
}
Related
I want to make a tiles based scrolling game in Visual Studio C# using forms. I know its not the best platform for this but those are set parameters. I suppose the easiest way to think of the end program is like pokemon 2d top down world scrolling.
I can create a 2d array of picture boxes and allocated images to them based on a text 2d array of tile ids. I can scroll the picture boxes and when they reach a certain place, jump back to the original location and display a shifted tile.
My issue is adding controls, it only adds a column rather than the full grid. I have tried using tables but with the same problem.
Has anyone done this type of large world scroller using VSC# and forms? Are there any tutorials or suggestions? Thanks.
EDIT - Code added'
public Form1()
{
InitializeComponent();
TableLayoutPanel wholescreen = new TableLayoutPanel();
wholescreen.Location = new System.Drawing.Point(0,0);
wholescreen.Size = new System.Drawing.Size(200,200);
wholescreen.RowCount = 2;
wholescreen.ColumnCount = 2;
Controls.Add(wholescreen);
PictureBox item = new PictureBox();
item.Size = new System.Drawing.Size(50, 50);
item.ImageLocation = "C:\\Users\\i.price\\Documents\\1.png";
for (int x = 0; x < 2; x++)
{
for (int y = 0; y < 2; y++)
{
item.Left = x * 50;
item.Top = y * 50;
wholescreen.Controls.Add(item,x,y);
}
}
}
'
another way i tried....'
int WIDTH = 3;
int HEIGHT = 3;
PictureBox[] grid = new PictureBox[9];
//PictureBox[,] grid = new PictureBox[3, 3];
//int[,] level1 = new int[2, 2] { { 1, 2 }, { 3, 4 } };
int playerx = 0;
public Form1()
{
InitializeComponent();
int y = 0;
int x = 0;
for (int cntr = 0; cntr < HEIGHT*WIDTH; cntr++)
{
if ((cntr % HEIGHT) == 0)
{
x++;
y = 0;
}
grid[cntr] = new PictureBox();
grid[cntr].Left = x * 50;
grid[cntr].Top = y * 50;
grid[cntr].ImageLocation = "C:\\Users\\i.price\\Documents\\1.png";
Controls.Add(grid[cntr]);
}
}
'
I think you are just creating one square and moving it around. Try...
private void Method2()
{
TableLayoutPanel wholescreen = new TableLayoutPanel();
wholescreen.BackColor = Color.AliceBlue;
wholescreen.Location = new System.Drawing.Point(0, 0);
wholescreen.Size = new System.Drawing.Size(200, 200);
wholescreen.RowCount = 2;
wholescreen.ColumnCount = 2;
Controls.Add(wholescreen);
PictureBox item;
// item.ImageLocation = "C:\\Users\\i.price\\Documents\\1.png";
for (int x = 0; x < 2; x++)
{
for (int y = 0; y < 2; y++)
{
item = new PictureBox();
item.Size = new System.Drawing.Size(50, 50);
item.BackColor = Color.Blue;
//item.Left = 0;
//item.Top = 0;
wholescreen.Controls.Add(item, x, y);
}
}
}
enter image description here
I have captured points data from bamboo slate,and converted them to Windows.UI.Input.Inking.InkStroke data.Then I put them in a InkPresenter.StrokeContainer rendered like this image above.Strokes sticked to each other,how can I seperate them?
This is my code below.
private void DataDisplay()
{
List<InkPoint> list = new List<InkPoint>();
List<InkStroke> strokes = new List<InkStroke>();
InkDrawingAttributes drawingAttributes1 = new InkDrawingAttributes();
drawingAttributes1.Color = Colors.Black;
drawingAttributes1.Size = new Size(1, 1);
InkStrokeBuilder builder = new InkStrokeBuilder();
builder.SetDefaultDrawingAttributes(drawingAttributes1);
inkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttributes1);
inkCanvas.InkPresenter.IsInputEnabled = true;
foreach (var item in data.Stroke)
{
string[] strArray = item.Split(',');
for (int i = 9; i <= strArray.Length - 5; i += 5)
{
float x = float.Parse(strArray[i]) / 30;
float y = float.Parse(strArray[i + 1]) / 30;
float pressure = float.Parse(strArray[i + 2]) / 1000;
Point point = new Point(x, y);
InkPoint ip = new InkPoint(point, pressure);
list.Add(ip);
}
Matrix3x2 matrix3X2 = new Matrix3x2(1, 0, 0, 1, 0, 0);
InkStroke newStroke = builder.CreateStrokeFromInkPoints(list, matrix3X2);
strokes.Add(newStroke);
}
inkCanvas.InkPresenter.StrokeContainer.AddStroke(strokes);
}
I want to create a 3D Graph in 4 quadrants form in C#.NET. For instant, I could do as shown below. If you see the corner of the chart begins with (-150, -200). I wish to start with (0,0) and the extend into 4 quadrant form.
Kindly enlighten me how can I transform this 3D graph in 4 quadrant form ?
Below is the corresponding code:
void prepare3dChart(Chart chart, ChartArea ca)
{
ca.Area3DStyle.Enable3D = true;
Series s = new Series();
chart.Series.Add(s);
s.ChartType = SeriesChartType.Bubble;
s.MarkerStyle = MarkerStyle.Diamond;
s["PixelPointWidth"] = "100";
s["PixelPointGapDepth"] = "1";
chart.ApplyPaletteColors();
addTestData(chart);
}
void addTestData(Chart chart)
{
Random rnd = new Random(9);
double x = 0, y = 0, z = 0;
for (int i = 0; i < 100; i++)
{
AddXY3d(chart.Series[0], x, y, z);
x = Math.Sin(i / 11f) * 88 + rnd.Next(3);
y = Math.Cos(i / 10f) * 88 + rnd.Next(5);
z = (Math.Sqrt(i * 2f) * 88 + rnd.Next(6));
}
}
int AddXY3d(Series s, double xVal, double yVal, double zVal)
{
int p = s.Points.AddXY(xVal, yVal, zVal);
s.Points[p].Color = Color.Transparent;
return p;
}
private void chart1_PostPaint(object sender, ChartPaintEventArgs e)
{
Chart chart = sender as Chart;
if (chart.Series.Count < 1) return;
if (chart.Series[0].Points.Count < 1) return;
ChartArea ca = chart.ChartAreas[0];
List<List<PointF>> data = new List<List<PointF>>();
foreach (Series s in chart.Series)
data.Add(GetPointsFrom3D(ca, s, s.Points.ToList(), e.ChartGraphics));
renderLines(data, e.ChartGraphics.Graphics, chart, true);
renderPoints(data, e.ChartGraphics.Graphics, chart, 6);
}
List<PointF> GetPointsFrom3D(ChartArea ca, Series s,
List<DataPoint> dPoints, ChartGraphics cg)
{
var p3t = dPoints.Select(x => new Point3D((float)ca.AxisX.ValueToPosition(x.XValue),
(float)ca.AxisY.ValueToPosition(x.YValues[0]),
(float)ca.AxisY.ValueToPosition(x.YValues[1]))).ToArray();
ca.TransformPoints(p3t.ToArray());
return p3t.Select(x => cg.GetAbsolutePoint(new PointF(x.X, x.Y))).ToList();
}
void renderLines(List<List<PointF>> data, Graphics graphics, Chart chart, bool curves)
{
for (int i = 0; i < chart.Series.Count; i++)
{
if (data[i].Count > 1)
using (Pen pen = new Pen(Color.FromArgb(64, chart.Series[i].Color), 2.5f))
if (curves) graphics.DrawCurve(pen, data[i].ToArray());
else graphics.DrawLines(pen, data[i].ToArray());
}
}
void renderPoints(List<List<PointF>> data, Graphics graphics, Chart chart, float width)
{
for (int s = 0; s < chart.Series.Count; s++)
{
Series S = chart.Series[s];
for (int p = 0; p < S.Points.Count; p++)
using (SolidBrush brush = new SolidBrush(Color.FromArgb(64, S.Color)))
graphics.FillEllipse(brush, data[s][p].X - width / 2,
data[s][p].Y - width / 2, width, width);
}
}
I want my 3D graph to have 4 quadrants like this:
Thanks #TaW. I got the code right.
void prepare3dChart(Chart chart, ChartArea ca)
{
ca.Area3DStyle.Enable3D = true;
ca.BackColor = Color.Transparent;
ca.AxisX.Minimum = -300;
ca.AxisX.Maximum = 300;
ca.AxisY.Minimum = -300;
ca.AxisY.Maximum = 300;
ca.AxisX.Crossing = 0; // move both axes..
ca.AxisY.Crossing = 0; // to the middle
ca.AxisX.Interval = 50;
ca.AxisY.Interval = 50;
ca.AxisX.MajorGrid.LineColor = Color.LightGray;
ca.AxisY.MajorGrid.LineColor = Color.LightGray;
chart.Series.Clear();
Series s = new Series();
chart.Series.Add(s);
s.ChartType = SeriesChartType.Bubble;
s.MarkerStyle = MarkerStyle.Diamond;
s["PixelPointWidth"] = "100";
s["PixelPointGapDepth"] = "1";
chart.ApplyPaletteColors();
addTestData(chart);
}
You can style the chart easily to look like this by moving both axes to the middle; this is done by setting their Crossings:
The code used is this:
ChartArea ca = chart1.ChartAreas[0];
ca.BackColor = Color.Transparent;
ca.AxisX.Minimum = -300;
ca.AxisX.Maximum = 300;
ca.AxisY.Minimum = -300;
ca.AxisY.Maximum = 300;
ca.AxisX.Crossing = 0; // move both axes..
ca.AxisY.Crossing = 0; // to the middle
ca.AxisX.Interval = 100;
ca.AxisY.Interval = 100;
ca.AxisX.MajorGrid.LineColor = Color.LightGray;
ca.AxisY.MajorGrid.LineColor = Color.LightGray;
Note that the real problem with MSChart in 3d-mode always remains the z-axis because there really isn't one. (If anybody is interested in how one can simulate it by having a lot of series see here. My example uses 32 series..)
You could draw it yourself, using the built-in function for the 3d conversions (TransformPoints) but this is a lot of tedious work, especially when it comes to labelling..
The updated code :
void prepare3dChart(Chart chart, ChartArea ca)
{
ca.Area3DStyle.Enable3D = true;
ca.BackColor = Color.Transparent;
ca.AxisX.Minimum = -300;
ca.AxisX.Maximum = 300;
ca.AxisY.Minimum = -300;
ca.AxisY.Maximum = 300;
ca.AxisX.Crossing = 0; // move both axes..
ca.AxisY.Crossing = 0; // to the middle
ca.AxisX.Interval = 50;
ca.AxisY.Interval = 50;
ca.AxisX.MajorGrid.LineColor = Color.LightGray;
ca.AxisY.MajorGrid.LineColor = Color.LightGray;
chart.Series.Clear();
Series s = new Series();
chart.Series.Add(s);
s.ChartType = SeriesChartType.Bubble;
s.MarkerStyle = MarkerStyle.Diamond;
s["PixelPointWidth"] = "100";
s["PixelPointGapDepth"] = "1";
chart.ApplyPaletteColors();
addTestData(chart);
}
Im new in C# WPF.
I want to create a Line in WPF C# with a Point array.
Like:
Point[] points =
{
new Point(3, 5),
new Point(1 , 40),
new Point(12, 30),
new Point(20, 2 )
};
Line myLine = new Line( points );
How can I do this?
if you want to draw it with Line, write a method, or you can use Polyline
public MainWindow()
{
InitializeComponent();
canvas.Children.Clear();
Point[] points = new Point[4]
{
new Point(0, 0),
new Point(300 , 300),
new Point(400, 500),
new Point(700, 100 )
};
DrawLine(points);
//DrawLine2(points);
}
private void DrawLine(Point[] points)
{
int i;
int count = points.Length;
for (i = 0; i < count - 1; i++)
{
Line myline = new Line();
myline.Stroke = Brushes.Red;
myline.X1 = points[i].X;
myline.Y1 = points[i].Y;
myline.X2 = points[i + 1].X;
myline.Y2 = points[i + 1].Y;
canvas.Children.Add(myline);
}
}
private void DrawLine2(Point[] points)
{
Polyline line = new Polyline();
PointCollection collection = new PointCollection();
foreach(Point p in points)
{
collection.Add(p);
}
line.Points = collection;
line.Stroke = new SolidColorBrush(Colors.Black);
line.StrokeThickness = 1;
canvas.Children.Add(line);
}
I've tried to make a method, which insert some numbers in a zedgraph. But it won't work.
This is my code:
string title = "Contemporary Quality";
string xaxis = "Amount";
string yaxis = "Percent";
zedGraphControl3.GraphPane.CurveList.Clear();
zedGraphControl3.GraphPane.GraphObjList.Clear();
GraphPane myPane = zedGraphControl3.GraphPane;
myPane.GraphObjList.Clear();
myPane.CurveList.Clear();
myPane.XAxis.Title.Text = xaxis;
myPane.Title.Text = title;
myPane.YAxis.Title.Text = yaxis;
myPane.XAxis.Scale.MinAuto = false;
myPane.XAxis.Scale.MinGrace = -0.5;
myPane.XAxis.Scale.Max = 16;
myPane.BarSettings.Type = BarType.PercentStack;
double[] x = new double[] { zg1.GraphPane.XAxis.Scale.Min, zg1.GraphPane.XAxis.Scale.Max };
double[] y = new double[] { 20, 20 };
ZedGraph.LineItem lineItem = new ZedGraph.LineItem("cursorY1", x, y, Color.Black, ZedGraph.SymbolType.None);
lineItem.Line.Style = System.Drawing.Drawing2D.DashStyle.Dash;
lineItem.IsSelectable = false;
lineItem.Label.IsVisible = false; // hides the cursor in the legend
zg1.GraphPane.CurveList.Add(lineItem);
y = new double[] { 40, 40 };
lineItem = new ZedGraph.LineItem("cursorY2", x, y, Color.Black, ZedGraph.SymbolType.None);
lineItem.Line.Style = System.Drawing.Drawing2D.DashStyle.Dash;
lineItem.IsSelectable = false;
lineItem.Label.IsVisible = false; // hides the cursor in the legend
zg1.GraphPane.CurveList.Add(lineItem);
y = new double[] { 60, 60 };
lineItem = new ZedGraph.LineItem("cursorY3", x, y, Color.Black, ZedGraph.SymbolType.None);
lineItem.Line.Style = System.Drawing.Drawing2D.DashStyle.Dash;
lineItem.IsSelectable = false;
lineItem.Label.IsVisible = false; // hides the cursor in the legend
zg1.GraphPane.CurveList.Add(lineItem);
y = new double[] { 80, 80 };
lineItem = new ZedGraph.LineItem("cursorY4", x, y, Color.Black, ZedGraph.SymbolType.None);
lineItem.Line.Style = System.Drawing.Drawing2D.DashStyle.Dash;
lineItem.IsSelectable = false;
lineItem.Label.IsVisible = false; // hides the cursor in the legend
zg1.GraphPane.CurveList.Add(lineItem);
PointPairList PPLa = new PointPairList();
PointPairList PPLb = new PointPairList();
PointPairList PPLc = new PointPairList();
PointPairList PPLd = new PointPairList();
PointPairList PPLf = new PointPairList();
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int f = 0;
List<string> newlistString = new List<string>();
DateTime end = dateTimePicker2.Value.Date;
DateTime start = dateTimePicker1.Value.Date;
newlistString = ctrscan.AnalyzeOldScans(start, end);
for (int h = 0; h <= (newlistString.Count - 1); h++)
{
if (newlistString[h].Equals("A"))
{
a = a + 1;
}
if (newlistString[h].Equals("B"))
{
b = b + 1;
}
if (newlistString[h].Equals("C"))
{
c = c + 1;
}
if (newlistString[h].Equals("D"))
{
d = d + 1;
}
if (newlistString[h].Equals("F"))
{
f = f + 1;
}
double aa = Convert.ToDouble(a);
double bb = Convert.ToDouble(b);
double cc = Convert.ToDouble(c);
double dd = Convert.ToDouble(d);
double ff = Convert.ToDouble(f);
PPLa.Add(h,aa);
PPLa.Add(h, bb);
PPLa.Add(h, cc);
PPLa.Add(h, dd);
PPLa.Add(h, ff);
}
Console.WriteLine(a+" "+b+" "+c+" "+d+" "+f);
BarItem myBara = myPane.AddBar("Quality A", PPLa, Color.Red);
BarItem myBarb = myPane.AddBar("Quality B", PPLb, Color.Blue);
BarItem myBarc = myPane.AddBar("Quality C", PPLc, Color.Gray);
BarItem myBard = myPane.AddBar("Quality D", PPLd, Color.Black);
BarItem myBarf = myPane.AddBar("Quality F", PPLf, Color.Pink);
zedGraphControl3.AxisChange();
zg1.AxisChange();
The output from the "consolewriteline" is: 0 15 56 4 9. And therefor I expect at least 4 bars on the graph. But nothing happens. Hope anyone knows..
Thanks.
PPLa.Add(h,aa);
PPLa.Add(h, bb);
PPLa.Add(h, cc);
PPLa.Add(h, dd);
PPLa.Add(h, ff);
needs to be:
PPLa.Add(h,aa);
PPLb.Add(h, bb);
PPLc.Add(h, cc);
PPLd.Add(h, dd);
PPLe.Add(h, ff);
i hope this will work for you