Is it possible to create zedgraph vertical marker? - c#

I wonder, is it possible to create vertical marker in zedgraph?
I want to render all chart points and make vertical marker as indicator of current position.

On a previous project, I used the following code to get that kind of effect.
int i = myPane.AddYAxis("");
myPane.YAxisList[i].Color = Color.Orange;
myPane.YAxisList[i].Scale.IsVisible = false;
myPane.YAxisList[i].MajorTic.IsAllTics = false;
myPane.YAxisList[i].MinorTic.IsAllTics = false;
myPane.YAxisList[i].Cross = pointOnXAxisThatIWantToMark;
In this case I add two axis to mark certain limits on my graph.

You can set the SymbolType of your curve to SymbolType.VDash.
For example, to set the symbol for a LineItem, you can either do it directly in the constructor (curve1 in the source code below), or you can customize it before assigning it to the curve (curve2).
This code:
var curve1 = new LineItem(null, new[] { 0.1, 0.5, 0.9 },
new[] { 0.8, 0.3, 0.1 }, Color.Blue, SymbolType.VDash);
zedGraphControl1.GraphPane.CurveList.Add(curve1);
var curve2 = new LineItem(String.Empty)
{
Points = new PointPairList(
new[] { 0.1, 0.5, 0.9 }, new[] { 0.2, 0.5, 0.9 }),
Color = Color.Red,
Symbol = new Symbol(SymbolType.VDash, Color.Black)
{ Size = 20f, Border = new Border(Color.Black, 6f)}
};
zedGraphControl1.GraphPane.CurveList.Add(curve2);
produces the following graph:

Related

UWP MapControl MapPolygon stroke not setting correctly

I'm placing multiple MapPolygons on a MapControl. The stroke for the MapPolygons do not set correctly. The stroke color for all polygons regardless of what layer they reside in binds to the polygon with the highest Z-index. I created an example using the UWP MapControl example from Microsoft:
https://learn.microsoft.com/en-us/windows/uwp/maps-and-location/display-poi
See "Add a shape" section.
I tried placing each polygon in a separate layer but it gives similar results.
It is worth noting that the Polygon FillColor parameter is unaffected only the stroke color and thickness.
XAML
<my:MapControl HorizontalAlignment="Left" x:Name="mapControl" MapServiceToken="..." Width="1650" Height="800" />
public BlankPage1()
{
this.InitializeComponent();
BasicGeoposition cityPosition = new BasicGeoposition() { Latitude = 34.8, Longitude = -116, Altitude = 0 };
Emitter_Position = new Geopoint(cityPosition);
mapControl.Center = Emitter_Position;
mapControl.ZoomLevel = 9;
mapControl.LandmarksVisible = true;
test_polygons();
}
public void test_polygons()
{
double centerLatitude = Emitter_Position.Position.Latitude;
double centerLongitude = Emitter_Position.Position.Longitude;
var MyHighlights = new List<MapElement>();
var mapPolygon = new MapPolygon
{
Path = new Geopath(new List<BasicGeoposition> {
new BasicGeoposition() {Latitude=centerLatitude+0.1, Longitude=centerLongitude-0.1 },
new BasicGeoposition() {Latitude=centerLatitude-0.1, Longitude=centerLongitude-0.1 },
new BasicGeoposition() {Latitude=centerLatitude-0.1, Longitude=centerLongitude+0.1 },
new BasicGeoposition() {Latitude=centerLatitude+0.1, Longitude=centerLongitude+0.1 },
}),
ZIndex = 2,
FillColor = Colors.Red,
StrokeColor = Colors.Blue,
StrokeThickness = 3,
StrokeDashed = false,
};
var mapPolygon2 = new MapPolygon
{
Path = new Geopath(new List<BasicGeoposition> {
new BasicGeoposition() {Latitude=centerLatitude+0.2, Longitude=centerLongitude-0.2 },
new BasicGeoposition() {Latitude=centerLatitude-0.2, Longitude=centerLongitude-0.2 },
new BasicGeoposition() {Latitude=centerLatitude-0.2, Longitude=centerLongitude+0.2 },
new BasicGeoposition() {Latitude=centerLatitude+0.2, Longitude=centerLongitude+0.2 },
}),
ZIndex = 1,
FillColor = Colors.Green,
StrokeColor = Colors.Yellow,
StrokeThickness = 3,
StrokeDashed = false,
};
MyHighlights.Add(mapPolygon);
MyHighlights.Add(mapPolygon2);
var HighlightsLayer = new MapElementsLayer
{
ZIndex = 1,
MapElements = MyHighlights
};
Result_Map.Layers.Add(HighlightsLayer);
}
The stroke color for mapPolygon2 shows as blue rather than yellow. If you flip the Zindex for the mapPolygons than the stroke for both polygons will be yellow. So what's the trick to get the stroke to set correctly when displaying multiple polygons?
This won't be impacted by the version of the OS you're targeting, but by the version of the OS you're running on. This was a known issue in OS versions prior to 1809, so it's been fixed for about one year. Updating to a more recent build of the OS should solve your issue. A recommended workaround if you can't update the OS would be to draw the polygon without a border, and then draw the border as a polyline in a separate call.

OxyPlot Change Interval On Zoom Level

I'm trying to make my plot change it's interval type depending on the level of zoom but I'm not sure how to achieve this. I'm using a DateTimeAxis and would like it to start at Days. Then zooming out would change from days to months, finally to years. Zooming in would change from Days to hours, maybe seconds if this type of behavior is even possible.
Currently I have my axes setup as follows:
public DateTimeAxis HorizontalAxis
{
get
{
return new DateTimeAxis
{
Position = AxisPosition.Bottom,
Minimum = DateTimeAxis.ToDouble(Start),
Maximum = DateTimeAxis.ToDouble(End),
MajorStep = double.NaN,
MinimumMajorStep = 0,
MinorStep = double.NaN,
MinimumMinorStep = 0,
AbsoluteMinimum = DateTimeAxis.ToDouble(Start),
AbsoluteMaximum = DateTimeAxis.ToDouble(End),
MinorIntervalType = DateTimeIntervalType.Hours,
IntervalType = DateTimeIntervalType.Days,
Title = " Date Time Axis Title "
};
}
}
public LinearAxis VerticalAxis
{
get
{
return new LinearAxis
{
Position = AxisPosition.Left,
Minimum = SetPoint - 4,
Maximum = SetPoint + 4,
MajorStep = double.NaN,
MinimumMajorStep = 0,
MinorStep = 0.5,
MinimumMinorStep = 0,
AbsoluteMinimum = SetPoint - 4,
AbsoluteMaximum = SetPoint + 4,
MinorTickSize = 0,
Title = " Linear Axis Title "
};
}
}
If this type of behavior is not possible I would also ask if there is a way to get hours to show when zooming in from days. When making a default plot this was the behavior I saw.
Thanks!
I know I just posted this question but perhaps there are other people who are interested in getting this type of behavior.
To dynamically change the axis I used the AxisChanged event described Here
From there I created an output message to see what properties were changing in the axes. I found that the Scale, Minor Step Size, and Major Step Size are what changes on zooming. Implementing a simple if statement to check the scale I was able to get the behavior I desired.
private async void Horizontal_AxisChanged(object sender, AxisChangedEventArgs e)
{
DateTimeAxis horizontal = sender as DateTimeAxis;
if(horizontal.Scale > 100)
{
horizontal.IntervalType = DateTimeIntervalType.Hours;
}
else if(horizontal.Scale < 100)
{
horizontal.IntervalType = DateTimeIntervalType.Days;
}
}

Winform MsChart secondary axis and stripline

I have a couple of problems with a MSChart plotted in a Winform.
I can't get axis Y2 values displayed on the right hand side of the chart, which should be the default - similar to this question
the stripline won't plot, and
is it possible to line up the zero values of axes Y1 and Y2?
Thanks for any help.
ChartArea TestChartArea = new ChartArea();
public void CreateChartArea()
{
TestChartArea.Name = "TestChartArea";
TestChartArea.BackColor = Color.LightGreen;
TestChartArea.Position = new ElementPosition { Height = 100, Width = 80, X = 2, Y = 5 };
//TestChartArea.Position = new ElementPosition { Auto = true };
TestChartArea.AxisY = new Axis
{
Enabled = AxisEnabled.True,
IsLabelAutoFit = true,
IsMarginVisible = true,
LabelStyle = new LabelStyle { Format = "P2", ForeColor = Color.DarkBlue, Font = new Font("Arial", 10, FontStyle.Regular) },
LineColor = Color.Black,
MajorGrid = new Grid { LineColor = Color.White, LineDashStyle = ChartDashStyle.Solid },
MajorTickMark = new TickMark { LineColor = Color.Black }
};
TestChartArea.AxisY2 = new Axis
{
Enabled = AxisEnabled.True,
IsLabelAutoFit = true,
IsMarginVisible = true,
LabelStyle = new LabelStyle { Format = "P2", ForeColor = Color.DarkBlue, Font = new Font("Arial", 10, FontStyle.Regular) },
LineColor = Color.Transparent,
MajorGrid = new Grid { LineColor = Color.Yellow, LineDashStyle = ChartDashStyle.Solid },
MajorTickMark = new TickMark { LineColor = Color.Blue }
};
TestChartArea.AxisX = new Axis
{
Enabled = AxisEnabled.True,
Crossing = 0,
LineWidth = 1,
IsLabelAutoFit = true,
IsMarginVisible = false,
LabelStyle = new LabelStyle { Angle=-45,Format = "N0", ForeColor = Color.Black, Font = new Font("Arial", 8, FontStyle.Regular) },
LineColor = Color.Black,
MajorGrid = new Grid { LineColor = Color.White, LineDashStyle = ChartDashStyle.Solid },
MajorTickMark = new TickMark { LineColor = Color.LightGray, Size = 4.0f },
Name="Spot"
};
}
public void PlotChart()
{
int[] Xseries = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
double[] AXJO = { 0.0025, 0.0015, -0.001, 0.002, 0.0045, -0.002, -0.003, 0.0001, -0.004, -0.0075 };
double[] ES = { 0.0020, 0.0010, -0.0005, 0.003, 0.0025, -0.001, -0.0015, 0.0005, -0.0032, -0.006 };
double[] Diff = new double[10];
// pair return
for (int i = 0; i < 10; i++)
{
Diff[i] = AXJO[i] - ES[i];
}
TestChart.BackColor = Color.LightGoldenrodYellow;
TestChart.BackSecondaryColor = Color.LightBlue;
if (TestChart.Series.IsUniqueName("AXJO"))
{
TestChart.Series.Add("AXJO");
TestChart.Series["AXJO"].YAxisType = AxisType.Primary;
TestChart.Series["AXJO"].Color = Color.Green;
TestChart.Series["AXJO"].ChartType = SeriesChartType.Line;
TestChart.Series["AXJO"].Points.DataBindXY(Xseries, AXJO);
TestChart.Series["AXJO"].ChartArea = "TestChartArea";
}
if (TestChart.Series.IsUniqueName("ES"))
{
TestChart.Series.Add("ES");
TestChart.Series["ES"].YAxisType = AxisType.Primary;
TestChart.Series["ES"].Color = Color.Red;
TestChart.Series["ES"].ChartType = SeriesChartType.Line;
TestChart.Series["ES"].Points.DataBindXY(Xseries, ES);
TestChart.Series["ES"].ChartArea = "TestChartArea";
}
if (TestChart.Series.IsUniqueName("Diff"))
{
TestChart.Series.Add("Diff");
TestChart.Series["Diff"].YAxisType = AxisType.Secondary;
TestChart.Series["Diff"].Color = Color.Blue;
TestChart.Series["Diff"].ChartType = SeriesChartType.Line;
TestChart.Series["Diff"].Points.DataBindXY(Xseries, Diff);
TestChart.Series["Diff"].ChartArea = "TestChartArea";
}
}
public void AddStripLine()
{
// add stripline at Diff=zero
StripLine ZeroDiff = new StripLine();
ZeroDiff.ForeColor = Color.Black;
ZeroDiff.BackColor = Color.Black;
ZeroDiff.StripWidth = 1;
ZeroDiff.BorderWidth = 2;
ZeroDiff.Interval = 0;
ZeroDiff.IntervalOffset = 10;
TestChart.ChartAreas["TestChartArea"].AxisY2.StripLines.Add(ZeroDiff);
}
private void button1_Click(object sender, EventArgs e)
{
PlotChart();
AddStripLine();
}
}
You asked about the unwanted placement of the AxisY2 by setting its Crossing property to 0
Simply not setting it, thus leaving it at the default double.NaN for automatically placing it at the right will resolve the issue..:
Crossing = double.NaN
To make a stripline show, it needs to start within the visible range of its axis. Offsetting it by 10 is way overboard for your data.. Also making it black is probably not what you want, unless you only want a thin line, not a colored area..
The basic rules for StripLines are:
When Interval = 0 only one stripline is shown at IntervalOffset with a width/height of StripWidth
When Interval > 0 many striplines are shown, going over the whole axis; unless you have a semi-tranparent color you need to make sure that StripWidth < Interval or else there is no space between them!
All measures are in axis-values; the types can be set with StripWidthType and IntervalType; useful especially when using one of the DateTime units.
To make the 0 values of both y-axes align, you need to tweak the Minimum and/or Maximum values of one or both axes. This may be a bit tricky and you will probably need to look into your data and take full control of spacing and placing the axis labels..

How to prevent axis from auto-scaling?

Each time I add new data to series, Y axis is panning/zooming automatically in order to fit new data into screen. How can I prevent Oxyplot from touching the axis? I would like to have the scale fixed all the time, no matter what data I feed to plot
As #Taw stated, the properties in oxyplot are the same:
plotModel.Axes.Add(new LinearAxis()
{
Position = AxisPosition.Left,
Minimum = 0,
Maximum = 10,
});
plotModel.Axes.Add(new LinearAxis()
{
Position = AxisPosition.Bottom,
Minimum = 0,
Maximum = 10,
});

Change Oxyplot Axisline color

I create a new Plot and its PlotModel with a black BackgroundColor
Then I create a new Axes. The X-Axis doesn't matter, it's invisible.
The Y-Axis is:
var valueAxisY = new OxyPlot.Axes.LinearAxis(AxisPosition.Left, minValue, maxValue)
{
AxislineThickness = 2,
AxislineColor = OxyColors.White,
MinorGridLinethickness = 2,
MajorGridLineThickness = 2,
MinorTickSize = 4,
MajorTickSize = 7,
TicklineColor = OxyColors.White,
FontSize = 40,
TextColor = OxyColors.White
}
Everything works BUT the Y-Axisline. It seems to stay black no matter what. The ticks starting 1-2 pixels on the left of where the line should be are white and have the correct length.
Is this the wrong parameter?
The trick was Undefined.
var valueAxisY = new OxyPlot.Axes.LinearAxis(AxisPosition.Left, minValue, maxValue)
{
LineStyle = LineStyle.Undefined
};
Somehow this is a visible, editable, continuous line.
If you define the axis line you should also hide the border arround plot area, because it is drawn over the axis line.
using model.PlotAreaBorderThickness = 0

Categories