ZedGraph filling areas - c#

I am using the ZedGraph control and want to fill one side of the graph function with some color and other side with other color.
PointPairList list1 = new PointPairList();
list1.Add(0, 4);
list1.Add(4, 0);
LineItem myCurve = myPane.AddCurve("y(n)", list1, Color.Red, SymbolType.Diamond);
//This filling bottom side.
myCurve.Line.Fill = new Fill(Color.White, Color.FromArgb(113, 255, 0, 0), 90F);
//How to fill the top side?

I'm not very clear on what you're asking - but hopefully the below will help. You said in comments
Can I fill some polygon area in Zedgraph?
So here's how...
var zed = new ZedGraph.ZedGraphControl { Dock = System.Windows.Forms.DockStyle.Fill };
var poly = new ZedGraph.PolyObj
{
Points = new[]
{
new ZedGraph.PointD(0, 0),
new ZedGraph.PointD(0.5, 1),
new ZedGraph.PointD(1, 0.5),
new ZedGraph.PointD(0, 0)
},
Fill = new ZedGraph.Fill(Color.Blue),
ZOrder = ZedGraph.ZOrder.E_BehindCurves
};
var poly1 = new ZedGraph.PolyObj
{
Points = new[]
{
new ZedGraph.PointD(1, 0),
new ZedGraph.PointD(0.25, 1),
new ZedGraph.PointD(0.5, 0),
new ZedGraph.PointD(1, 0)
},
Fill = new ZedGraph.Fill(Color.Red),
ZOrder = ZedGraph.ZOrder.E_BehindCurves
};
zed.GraphPane.AddCurve("Line", new[] { 0.0, 1.0 }, new[] { 0.0, 1.0 }, Color.Green);
zed.GraphPane.GraphObjList.Add(poly1);
zed.GraphPane.GraphObjList.Add(poly);
Results in
Hopefully this will point you in the right direction!
(Code in VB as requested via http://converter.telerik.com/ - no guarentee of the VB code working or even compiling!)

Related

Why is my reversed MagnitudeAxis Polar Plot not rendering with Oxyplot?

I'm trying to create a Polar Plot with Oxyplot in my WPF application. I want the MagnitudeAxis to be reversed so I made the StartPosition = 1 and the EndPosition = 0. However this causes the plot not to render. It looks it may be due to the variables a0 and a1 being set to 0 in the UpdateTransform() method in MagnitudeAxis.cs but it may be something else (not exactly sure what all these variables represent).
Here's my code to set up the polar plot:
/// dictionary of angles: magnitudes
dict = {-180: -18, -179: -17.9, ... , 0: 0, ... , 178: -17.8, 179: -17.9}
PlotModel myPlot = new PlotModel
{
Title = "Polar Plot",
PlotType = PlotType.Polar,
PlotAreaBorderThickness = new OxyThickness(0),
};
var series1 = new ScatterSeries
{
Title = "Polar Series",
MarkerType = MarkerType.Circle,
MarkerSize = 3,
MarkerFill = OxyColor.FromRgb(255, 0, 0),
};
var axis1 = new AngleAxis
{
StartPosition = 1,
EndPosition = 0,
StartAngle = 270,
EndAngle = -90,
Title = "Angle",
LabelFormatter = d => $"{d}",
MajorStep = 30,
Minimum = -180,
Maximum = 180,
MinorGridlineStyle = LineStyle.None,
};
var axis2 = new MagnitudeAxis
{
/// here's where I set the Start and End Position
StartPosition = 1,
EndPosition = 0,
MajorStep = 6,
Title = "Magnitude",
MinorGridlineStyle = LineStyle.None,
Minimum = dict.Values.Min();
Maximum = dict.Values.Max()
};
foreach (KeyValuePair<double, double> keyValuePair in dict)
{
series1.Points.Add(new ScatterPoint(keyValuePair.Value, keyValuePair.Key));
}
myPlot.Axes.Add(axis1);
myPlot.Axes.Add(axis2);
myPlot.Series.Add(series1);
This is what I get when the plot tries rendering:
This is what I get when I use default Start/End Positions:
What I want is the default plot with 0 in the center and -18 on the edge instead.
This is my first question ever on SO, so let me know if there's any other information I should provide.

Sharpdx D3D9 nothing draw

I try to follow their examples on github and i just want to draw a line. But when the window opens, there only a blackscreen. I dont know what i did wrong.
Here is my source code.
Thank you for helping !
static void Main()
{
var form = new RenderForm("Test");
int width = form.ClientSize.Width;
int height = form.ClientSize.Height;
var device = new Device(new Direct3D(), 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters(width, height) { PresentationInterval = PresentInterval.One });
Line line = new Line(device);
RawVector2[] vertices =
{
new RawVector2(10, 10),
new RawVector2(10, 10)
};
RenderLoop.Run(form, () =>
{
device.Clear(ClearFlags.Target, new RawColorBGRA(0, 0, 0, 1), 1.0f, 0);
device.BeginScene();
line.Width = 10;
line.GLLines = true;
line.Antialias = false;
line.Draw(vertices, new RawColorBGRA(254, 254, 254, 1));
device.EndScene();
device.Present();
});
}
This might not be your error but it won't help matters because even if there are no errors you will see very little. I have used it but only in a window context and I followed https://github.com/Dan6040/SharpDX-Rastertek-Tutorials because I was coming from C++ Unreal, Raw DX9, and C# Unity, XNA framework.
Your vertices are drawing a 1-pixel dot because you need 2 vectors at different locations to draw a line
[
new RawVector2(10, 10),
new RawVector2(10, 10)
]
That is saying draw from x:10 y:10 to x:10 y:10
try:
[
new RawVector2(10, 10),
new RawVector2(30, 30)
]
So to better explain to draw a triangle you need 3 points and 3 lines, but to draw each line you need points in your ordering
[
new RawVector2(10, 10),
new RawVector2(10, 30),
new RawVector2(30, 30),
new RawVector2(10, 10)
]
So that works by saying draw from 10,10 to 10,30 then to 30,30 and finally back to 10,10
Just to note this is why Games engines don't work through arrays of points they are arrays of pointers to points so you only have the point objects in memory once and you just using pointers to them E.G
static void Main()
{
var form = new RenderForm("Test");
int width = form.ClientSize.Width;
int height = form.ClientSize.Height;
var device = new Device(new Direct3D(), 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters(width, height) { PresentationInterval = PresentInterval.One });
Line line = new Line(device);
RawVector2[] TrianglePoints=
{
new RawVector2(10, 10),
new RawVector2(10, 30),
new RawVector2(30, 30)
};
RawVector2[] vertices = {
TrianglePoints[0],
TrianglePoints[1],
TrianglePoints[2],
TrianglePoints[0]
}
RenderLoop.Run(form, () =>
{
device.Clear(ClearFlags.Target, new RawColorBGRA(0, 0, 0, 1), 1.0f, 0);
device.BeginScene();
line.Width = 10;
line.GLLines = true;
line.Antialias = false;
line.Draw(vertices, new RawColorBGRA(254, 254, 254, 1));
device.EndScene();
device.Present();
});
}

UWP C#: Adding MapPolygon to MapControl

I am trying to add a polygon to my map by using the following code example (retrieved from https://learn.microsoft.com/en-us/windows/uwp/maps-and-location/display-poi#add-a-shape):
public void HighlightArea() {
double centerLatitude = myMap.Center.Position.Latitude;
double centerLongitude = myMap.Center.Position.Longitude;
var mapPolygon = new MapPolygon
{
Path = new Geopath(new List<BasicGeoposition> {
new BasicGeoposition() {Latitude=centerLatitude+0.0005, Longitude=centerLongitude-0.001 },
new BasicGeoposition() {Latitude=centerLatitude-0.0005, Longitude=centerLongitude-0.001 },
new BasicGeoposition() {Latitude=centerLatitude-0.0005, Longitude=centerLongitude+0.001 },
new BasicGeoposition() {Latitude=centerLatitude+0.0005, Longitude=centerLongitude+0.001 },
}),
ZIndex = 1,
FillColor = Colors.Red,
StrokeColor = Colors.Blue,
StrokeThickness = 3,
StrokeDashed = false,
};
// Add MapPolygon to a layer on the map control.
var MyHighlights = new List<MapElement>();
MyHighlights.Add(mapPolygon);
var HighlightsLayer = new MapElementsLayer
{
ZIndex = 1,
MapElements = MyHighlights
};
myMap.Layers.Add(HighlightsLayer);
}
The polygon is shown on the map initially, but it disappears within 2 seconds from when it appeared (it fades away). I have successfully added a MapPolyline that sticks to the map by using an example I retrieved from the same link, which is why I cannot understand why the MapPolygon will not stick.
What may cause the polygon to fade away?

Misalignment of two chart areas

I was trying to overlap two chart areas. They would share the same x values, but Y would have different values and scales.
Here is outcome of my code:
As you can see red series is not in alignment with green series.I was searching this site for answers, but couldn't find one that worked. Could someone explain me why they don't align?
Code:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace TestGraph
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
#region Data
// Creating first series
Series s1 = new Series();
s1.Name = "Values";
s1.ChartType = SeriesChartType.Column;
s1.XValueType = ChartValueType.DateTime;
s1.Color = Color.Green;
s1.BorderWidth = 2;
// Hard Coding test values
DataPoint[] values =
{
new DataPoint(new DateTime(2017, 8, 1).ToOADate(), 10),
new DataPoint(new DateTime(2017, 8, 2).ToOADate(), 11),
new DataPoint(new DateTime(2017, 8, 3).ToOADate(), 12),
new DataPoint(new DateTime(2017, 8, 4).ToOADate(), 13),
};
// Adding vales to s1
foreach (DataPoint p in values)
{
s1.Points.Add(p);
}
// Creating second series
Series s2 = new Series();
s2.Name = "Values 2";
s2.ChartType = SeriesChartType.Column;
s2.XValueType = ChartValueType.DateTime;
s2.Color = Color.Red;
s2.BorderWidth = 2;
// Hard Coding test values
DataPoint[] values2 =
{
new DataPoint(new DateTime(2017, 8, 1).ToOADate(), 0.1),
new DataPoint(new DateTime(2017, 8, 2).ToOADate(), -0.2),
new DataPoint(new DateTime(2017, 8, 3).ToOADate(), -0.7),
new DataPoint(new DateTime(2017, 8, 4).ToOADate(), 13),
};
// Adding vales to s2
foreach (DataPoint p in values2)
{
s2.Points.Add(p);
}
#endregion
#region Charts
// Initializing chart
Chart mainChart = new Chart();
ChartArea area = new ChartArea();
ChartArea area2 = new ChartArea();
Controls.Add(mainChart);
mainChart.Dock = DockStyle.Fill;
// Adding areas to mainChart
mainChart.ChartAreas.Add(area);
mainChart.ChartAreas.Add(area2);
// Adding series to areas
s1.ChartArea = area.Name;
s2.ChartArea = area2.Name;
mainChart.Series.Add(s1);
mainChart.Series.Add(s2);
// Aligning areas
// Overlapping area2 with area
area2.AlignmentStyle = AreaAlignmentStyles.All;
area2.AlignmentOrientation = AreaAlignmentOrientations.All;
area2.AlignWithChartArea = area.Name;
// Scale actualization
area2.RecalculateAxesScale();
area.RecalculateAxesScale();
// Defining Y scale
area2.AxisY.Maximum = 2;
area2.AxisY.Minimum = -2;
area2.BackColor = Color.Transparent;
// Disabling unnecessary graphics
area2.BackGradientStyle = GradientStyle.None;
area2.AxisX.IsMarginVisible = false;
area2.AxisX.LabelStyle.Enabled = false;
area2.AxisY.LabelStyle.Enabled = false;
area2.AxisX.Enabled = AxisEnabled.False;
area2.AxisY.Enabled = AxisEnabled.False;
// Resizing chart back to 100%
area.Position = new ElementPosition(0, 0, 100, 100);
#endregion
}
}
}
One of your chart has AxisX.IsMarginVisible set to true, the other to false, hence the mismatch.
However, if you are trying to plot overlapping series, why are you not adding them to the same chart area instead of going through all this trouble?

Heat series graph: order in gradient bar

I am new to livechart and I have made the following basic graphic in livechart. However, I have 2 doubts about it.
using System;
using System.Windows.Forms;
using System.Windows.Media;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
namespace heatmap
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var converter = new System.Windows.Media.BrushConverter();
var brush = (Brush)converter.ConvertFromString("#000000");
var r = new Random();
cartesianChart1.Series.Add(new HeatSeries
{
Values = new ChartValues<HeatPoint>
{
new HeatPoint(0, 0, 0.25),
new HeatPoint(0, 1, 0.5),
new HeatPoint(0, 2, 0.5),
new HeatPoint(0, 3, 1),
new HeatPoint(1, 0, 0.5),
new HeatPoint(1, 1, 0.5),
new HeatPoint(1, 2, 1),
new HeatPoint(1, 3, 0.5),
//"Robyn Williamson"
new HeatPoint(2, 0, 0.5),
new HeatPoint(2, 1, 1),
new HeatPoint(2, 2, 0.5),
new HeatPoint(2, 3, 0.5),
new HeatPoint(3, 0, 1),
new HeatPoint(3, 1, 0.5),
new HeatPoint(3, 2, 0.25),
new HeatPoint(3, 3, 0.25),
},
Fill=brush,
Stroke=brush,
Foreground = brush,
FontSize=20,
DataLabels = true,
// LabelPoint=val=>"hola",
//The GradientStopCollection is optional
//If you do not set this property, LiveCharts will set a gradient
GradientStopCollection = new GradientStopCollection
{
new GradientStop(Color.FromRgb(255, 255, 255), 0),
new GradientStop(Color.FromRgb(0, 255, 0), .25),
new GradientStop(Color.FromRgb(7, 193, 67), .5),
new GradientStop(Color.FromRgb(0, 128, 0), .75),
new GradientStop(Color.FromRgb(0, 60, 31), 1),
},
});
cartesianChart1.AxisX.Add(new Axis
{
Position = AxisPosition.RightTop,
LabelsRotation = 0,
FontSize=15,
Labels = new[]
{
"variable rent",
"int tax.",
"Real state",
"money"
},
Separator = new Separator { Step = 1 }
});
cartesianChart1.AxisY.Add(new Axis
{
FontSize = 15,
Labels = new[]
{
"Money",
"Real state",
"int tax",
"variable rent"
}
});
}
}
}
Output:
How can you reverse the order of the gradient bar? 1 in the top and 0.25 in bottom.
Is it possible for each HeatPoint to place a tooltip or a color for each label(1 label white and other label yellow)?
thanks to all

Categories

Resources