about xyplot-wpf y axis alignment - c#

I do a project to show multi signal waves vertically arrangement。when the signal type is different(bool vs unsigned short)(means max value different)。the two signals y axis cant be aligned in x direction(because the max y value string occupy different space),something like this
I hope 2 solutions
the max y value text can be placed in the right of y axis
the max y value can be set to occupy same space(max value 1 occupy 5 characters padleft with empty,max value 65535 occupy 5 characters)
this is my code:
var series1 = new LineSeries { Title = serietitle, MarkerType = MarkerType.Circle };
var dateTimeAxis1 = new DateTimeAxis() { Minimum = DateTimeAxis.ToDouble(DateTime.Now), Maximum = DateTimeAxis.ToDouble(DateTime.Now.AddHours(1)) };
//dateTimeAxis1.Title = "Time";
model.Axes.Add(dateTimeAxis1);
model.Series.Add(series1);
LinearAxis leftAxis = new LinearAxis()
{
Position = AxisPosition.Left,
AbsoluteMaximum= maxy,
IsAxisVisible = true, //
Minimum = 0,
Maximum = maxy,
Title = "SigValue",//
IsZoomEnabled = false,//
};
model.Axes.Add(leftAxis);

Related

In the ms chart - winform, I want the RangeBar graph to be centered on the x-axis

In the ms chart, I want the RangeBar graph to be centered on the x-axis.
Only number 5 is in the middle and the other numbers are not middle children. I want to center this.
This happens when you adjust the PixelPointWidth.
When set to 1, it goes to the center, but the thickness is too small.
private void AddSerise(StartAndEndTime startAndEndTime)
{
int z = 0;
if (searchDeviceId.Contains(startAndEndTime.DeviceID))
{
z = searchDeviceId.IndexOf(startAndEndTime.DeviceID);
}
else
{
Series series2 = new Series(startAndEndTime.DeviceID);
mainChart.Series.Add(series2);
searchDeviceId.Add(startAndEndTime.DeviceID);
z = searchDeviceId.IndexOf(startAndEndTime.DeviceID);
}
mainChart.Series[startAndEndTime.DeviceID].ChartArea = "MainArea";
// mainChart.Series[startAndEndTime.DeviceID].Label = startAndEndTime.DeviceID;
//mainChart.Series[startAndEndTime.DeviceID].IsVisibleInLegend = true;
mainChart.Series[startAndEndTime.DeviceID].ChartType = SeriesChartType.RangeBar;
mainChart.Series[startAndEndTime.DeviceID].AxisLabel = z.ToString();
mainChart.Series[startAndEndTime.DeviceID].LegendText = startAndEndTime.DeviceID + "." + startAndEndTime.EventID;
mainChart.Series[startAndEndTime.DeviceID].Points.AddXY(z, startAndEndTime.startTime.ToOADate(), startAndEndTime.endTime.ToOADate());
mainChart.Series[startAndEndTime.DeviceID]["PixelPointWidth"] = "50";
}

C# Windows Forms Chart Always Display Zero in YAxis

I draw some charts using DataVisualization.Charting.Chart. All of my charts have inverse Y range.
For Example "-20 to 20" or "-150 to 150". It means that Zero is always in the middle of Y range, there is no problem in drawing but the chart never makes a label for Zero.
For Example I have this labels -20,-15,-10,-5,5,10,15,20. I always want to see the Zero in Y axis labels. See the image:
I did it using CustomLabels :
int maxRange = 20;
int yInterval = 5;
var minRange = (maxRange * -1);
area.AxisY.Minimum = minRange;
area.AxisY.Maximum = maxRange;
area.AxisY.LabelStyle.Format = "#";
area.AxisY.Interval = yInterval;
int yVal = minRange;
while (yVal <= maxRange)
{
area.AxisY.CustomLabels.Add(yVal - 0.5, yVal + 0.5, yVal.ToString());
yVal += yInterval;
}
for this min & max must in 10s series
chart.ChartAreas[0].AxisX.Interval = 10;
chart.ChartAreas[0].AxisY.Interval = 10;

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,
});

C# Excel Chart can't set serie scale

I'm trying to draw a threshold (1 line from left to right). To do so I add the threshold value twice and the value 0 and 1 for xValues then set the scale of X to be from 0 to 1.
public static void AddThreshold(Chart xlChart, double value, string name, int color, bool secondary)
{
Series series = xlChart.SeriesCollection().NewSeries();
series.Name = name;
series.XValues = new List<int>() { 0, 1 }.ToArray();
series.Values = new List<double>() { value, value }.ToArray();
Axis xAxis, yAxis;
if (secondary)
{
series.AxisGroup = XlAxisGroup.xlSecondary;
xAxis = (Axis)xlChart.Axes(XlAxisType.xlCategory, XlAxisGroup.xlSecondary);
yAxis = (Axis)xlChart.Axes(XlAxisType.xlValue, XlAxisGroup.xlSecondary);
}
else
{
xAxis = (Axis)xlChart.Axes(XlAxisType.xlCategory, XlAxisGroup.xlPrimary);
yAxis = (Axis)xlChart.Axes(XlAxisType.xlValue, XlAxisGroup.xlPrimary);
}
xAxis.MinimumScale = 0;//getting COM error here
xAxis.MaximumScale = 1;
yAxis.Delete();
series.ChartType = XlChartType.xlXYScatterLinesNoMarkers;
series.MarkerSize = 3;
series.Border.LineStyle = XlMarkerStyle.xlMarkerStyleDash;
series.Border.Color = color;
}
But I'm always getting a COM error and can't figure out the problem. To make things more annoying the exact method was working in a different project (don't ask about it because the code there was partially deleted by mistake and I am not rewriting it).
You can't set min and max of an axis if it's not a value type of axis, and only XY Scatter charts have an X axis that is a value axis. You need to specify the chart type of the added series as XY Scatter before setting the axis scale.
So move this:
series.ChartType = XlChartType.xlXYScatterLinesNoMarkers;
above this:
xAxis.MinimumScale = 0;

Draw date on X axis and time on Y axis using ZedGraph and C#

In ZedGraph, how do I draw a time (like 00:00, 02:00, 04:00, etc.) on the Y axis and date (like 12-Apr-11, 13-Apr-11, 14-Apr-11, etc.) on the X axis?
The bar settings has been set to BarType.Stack.
Sample code will be very helpful.
Here is a sample that I constructed. I was not sure what sort of data you would plot along the Y Axis using a time format except for something like an accrued amount of time (such as number of hours employees worked).
ZedGraph uses an XDate format for time along the axes, which are doubles converted from datetimes. However in a stacked bar, I am not sure if ZedGraph can aggregate the times properly (I couldn't get it to work). Thus, in my example I used a Linear type for the Y Axis and changed the format so that it displays as hours and minutes.
Note that the min and max of both axes' scales have been set. This is especially important along the X axis, as the auto setting gets it wrong. Some of the other settings I specify clean up the minor tic marks, etc.
Here's an example showing a stacked bar graph for number of hours worked by three employees during each day:
const int NumberOfBars = 5;
GraphPane myPane = zedGraphControl1.GraphPane;
myPane.Title.Text = "Employee Hours";
myPane.BarSettings.Type = BarType.Stack;
myPane.BarSettings.ClusterScaleWidth = 1D;
// X AXIS SETTINGS
myPane.XAxis.Title.Text = "Date";
myPane.XAxis.Type = AxisType.Date;
myPane.XAxis.Scale.Format = "dd-MMM-yy";
myPane.XAxis.Scale.MajorUnit = DateUnit.Day;
myPane.XAxis.Scale.MajorStep = 1;
myPane.XAxis.Scale.Min = new XDate(DateTime.Now.AddDays(-NumberOfBars));
myPane.XAxis.Scale.Max = new XDate(DateTime.Now);
myPane.XAxis.MajorTic.IsBetweenLabels = true;
myPane.XAxis.MinorTic.Size = 0;
myPane.XAxis.MajorTic.IsInside = false;
myPane.XAxis.MajorTic.IsOutside = true;
// Y AXIS SETTINGS
myPane.YAxis.Title.Text = "Hours Worked";
myPane.YAxis.Type = AxisType.Linear;
myPane.YAxis.Scale.Format = #"00:\0\0";
myPane.YAxis.Scale.Min = 0;
myPane.YAxis.Scale.Max = 24;
myPane.YAxis.Scale.MajorStep = 1;
myPane.YAxis.MinorTic.Size = 0;
// Construct some sample data
Random r = new Random();
List<double> DatesX = new List<double>();
double[] JohnHours = new double[NumberOfBars];
double[] JoanHours = new double[NumberOfBars];
double[] JaneHours = new double[NumberOfBars];
for (int i = 0; i < NumberOfBars; i++)
{
DatesX.Add(new XDate(DateTime.Today.AddDays(-i)));
JohnHours[i] = r.Next(1, 9);
JoanHours[i] = r.Next(1, 9);
JaneHours[i] = r.Next(1, 9);
}
myPane.AddBar("John", DatesX.ToArray(), JohnHours, Color.Red);
myPane.AddBar("Joan", DatesX.ToArray(), JoanHours, Color.Blue);
myPane.AddBar("Jane", DatesX.ToArray(), JaneHours, Color.Green);

Categories