With LiveCharts I create an X/Y graph:
X-axis: Time
Y-axis: symmetrical values output from the zero axis to MinValue and MaxValue.
The min/max values are set as follows:
if (Math.Abs(newValueY) > maxValueY)
{
maxValueY = Math.Abs(newValueY);
MaxValue = maxValueY;
MinValue = -maxValueY;
}
My problem is that the grid is not displayed symmetrically. The zero axis is not displayed. Is there any way to configure LiveCharts to draw the grid up and down from zero axis instead of starting at MinValue?
Thanks for any hints!
Markus
Related
I am new to C# winform. As title, my problem is how to make the points more compact in fastpoint chart. To make it clear, how to proportionally reduce the distance of the blue points like the red line segments shown in the image; that is, make the X axis more compact:
I have searched and found a lot of information about control the interval of X or Y axis labels but which is not the situation here.
You can control the range of data values for each Axis by setting their Minimum and Maximum values.
The syntax is:
someChart.ChartAreas[CAIndexOrName].AxisX.Minimum = someDoubleValue;
Let's prepare a chart to show one day:
Axis ax = chart.ChartAreas[0].AxisX; // a short reference
ax.IntervalType = DateTimeIntervalType.Hours;
ax.Interval = 1;
To set the properties to some DateTime values you need to convert them to doubles; for this conversion there are two built-in functions: DateTime.ToOADate and, to reverse DateTime.FromOADate
This makes the x-axis display 24 hours:
DateTime dt = DateTime.Today;
ax.Minimum = dt.ToOADate();
ax.Maximum = (dt.AddHours(24)).ToOADate();
ax.LabelStyle.Format = "H:mm"; // optional
You also may want to control the data type of the series values:
Series s = chart.Series[0];
s.XValueType = ChartValueType.DateTime; // or some other type, maybe Time
Note you you can also control both the Interval of the Labels and TickMarks and Gridlines on each axis but also set an Offset to start them a little earlier or later..
I have a line chart in my form that get its data by the code comes in the following
foreach (var series in chart2.Series)
{
series.Points.Clear();
}
Series series2 = chart2.Series[0];
SqlCommand cmdchartline = new SqlCommand(myquery, Con);
SqlDataReader reader2 = cmdchartline.ExecuteReader();
while (reader2.Read())
{
chart2.Series[0].Points.AddXY(reader2["myx"].ToString(), reader2["myy"]);
}
I need to connect (0,5000) as a first point to the chart below I mean chart start from (0,5000) on Y axis
You are adding the x-values as strings.
This is usually (*) wrong as they all are 0 now.
Note: The labels still show the strings but otherwise they are useless.
Change this
chart2.Series[0].Points.AddXY(reader2["myx"].ToString(), reader2["myy"]);
to this:
chart2.Series[0].Points.AddXY(reader2["myx"], reader2["myy"]);
If the fields 'myx' and 'myy' are numbers or dates you now can find the maximum for the DataPoint values:
double maxX = chart2.Series[0].Points.Max(x => x.XValues);
double maxY = chart2.Series[0].Points.Max(x => x.YValues[0]);
Now you can add (or insert) the extra DataPoint; you need to decide on its x-value though!
As I wrote the finding the Y-value is simple but the x-values may be less simple. If you don't need the x-values you can keep them as string or, better, you can make the Series 'Indexed'..:
chart2.Series[0].IsXValueIndexed = true;
Then you can insert the extra point to the beginning like this:
chart2.Series[0].Points.InsertXY(0, 0, maxY);
Note that when keeping the x-values as strings you can't:
use a formatting string for the axis or datapoint labels
use a zoom range based on the values (Axis.ScaleView)
use a display range (Axis.Minimum/Maximum)
do any calulations with the x-values
And you can't hope the chart would display the values in a nice proportional manner; instead they will have sit at the same intervals.
(*) Sometimes none of this is needed, like when the x-values are names or persons or cities etc..
I want to use a datetimeaxis for the Y-axis of an Oxyplot heatmapseries (in winforms). The API allows me to add the axis to the PlotModel, but does not do much good since the y-value is mapped off of the integral column index of a matrix of doubles - the y values come out to around Jan. 1900.
How can I use times for the y data on the heat map?
The workaround to make this happen is not too difficult. When setting up the chart, create 2 axes: one for the time, and another for the integral index of the HeatMapSeries input.
DateTimeAxis dateTimeAxis;
HeatMapSeries series;
....
//set up the time axis for y
dateTimeAxis = new DateTimeAxis();
dateTimeAxis.Position = AxisPosition.Left;
dateTimeAxis.Key = "dateTimeAxis";
plotModel.Axes.Add(dateTimeAxis);
//set up a shadow axis for the HeatMapSeries
var linearAxis = new LinearAxis();
linearAxis.Position = AxisPosition.Left;
linearAxis.Key = "linearAxis";
plotModel.Axes.Add(linearAxis);
series.YAxisKey = linearAxis.Key;
Next, the assigned y-axis will have to be hidden - but we can't access the YAxis property until the plot has been updated:
//hide the linear axis
plotModel.Updated += (sender, e) =>
{
series.YAxis.IsAxisVisible = false;
};
Finally, when setting the heat map data, simply create the desired mapping from the matrix index to time. Then adjust the y-scale. For example:
public void UpdateData(double[,] data)
{
series.Data = data;
//adjust date/time axis
int numOfMinutes = data.GetLength(1);
dateTimeAxis.Minimum = DateTimeAxis.ToDouble(DateTime.Now);
dateTimeAxis.Maximum DateTimeAxis.ToDouble(DateTime.Now.AddMinutes(numOfMinutes));
}
I have not yet seen a way to do this directly in OxyPlot
I have an MS chart control with several StepLine series and one column series.
All series are plotted by doing:
double yvalue = ...;
Series[seriesName].Points.AddXY(DateTime.Now, new object[] {yvalue});
the series in question is defined in the designer:
series31.ChartArea = "ChartArea1";
series31.Color = System.Drawing.Color.BlueViolet;
series31.CustomProperties = "EmptyPointValue=Zero, MaxPixelPointWidth=1";
series31.Legend = "Legend1";
series31.MarkerSize = 1;
Step lines plot fine, however the column series is displayed with a line going from the bottom of the chart to the value (in the screen cap below, the value is typically around 2.0).
How can I get the series to just draw a line that starts at 0 on the y-axis?
I assume you want a chart that will start from zero in Y-Axis at the bottom.
chartArea.AxisY.Minimum = 0;
if you do so,then you will not see the value less then zero in chart.you can also set the Maximum of
Y-Axis.
chartArea.AxisY.Minimum = 0;
chartArea.AxisY.Maximum = 10;
above code will show only the values from 0 to 10.
I have some data I need to display using MSChart, I am looking to plot data which is one of the following values taken at a particular datetime:
Low
Low-Medium
Medium
Medium-High
High
So I am looking for datetime along the X axis and the above values on Y
When I try and plot them something like this....
mySeries.Points.AddXY(dateA, "Low");
mySeries.Points.AddXY(dateB, "Low-Medium");
mySeries.Points.AddXY(dateC, "Medium");
The chart obviously doesn't have any idea that Medium show be a larger bar than Low.
How can I specify this range of values for the Y Axis?
You can set numeric values as suggested in Kyle answer and then change the Y labels e.g.:
chart1.ChartAreas[0].AxisY.CustomLabels.Add(0, 1, "LOW");
// it means: on Y range = [0, 1] show the label "LOW" ...
chart1.ChartAreas[0].AxisY.CustomLabels.Add(2, 3, "MEDIUM");
chart1.ChartAreas[0].AxisY.CustomLabels.Add(3, 4, "HIGH");
Give the different values a numeric value:
mySeries.Points.AddXY(dateA, 1); // Low
mySeries.Points.AddXY(dateB, 2); // Low-Medium
mySeries.Points.AddXY(dateC, 3); // Medium
I'm not sure how you would show the named values on the Y axis though.