Why does DataPoint.AxesLabel not appear on the chart? (MS Chart) - c#

I'm adding my points to the chart like this:
var point = new DataPoint(xValue.TimeStamp.Ticks, yValue);
point.AxisLabel = "someString";
series.Points.Add(point);
But the AxisLabel doesn't appear on my chart.
When I'm using this code the labels appear but as double and not as i want:
series.Points.AddXY(xValue.TimeStamp.Ticks, yValue);
My AxisValueTyp is set to double.
Is there something i miss? Do I have to set something within the labelsettings of the chartArea X Axis?

Ticks are of type long. If you are using Ticks for your X-Axis you can use the
series.Points.AddXY(xValue.TimeStamp.Ticks, yValue);
format to add the data points.
You didn't say what format you want. To set the format from the standard axis format double to a more suitable number format use e.g.
yourChartArea.AxisX.LabelStyle.Format = "###,###,###,##0";
for the X-Axis of yourChartArea.

Related

LiveCharts: symmetrical Y-graph around the zero axis

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

Formatting Data into Chart C# WPF

I have a database where a user can select a date range and pull the data back. This is saved into three columns, Date, Time, Value. if it's temperature it's a Line Chart, if it's a Meter it's Bar Chart.
I have the below code but it's not working, I'm getting confused how to send this data.
Setting different values:
eChartType chartType = eChartType.ColumnClustered;
if (plotName.Contains("temp") || plotName.Contains("Temp"))
{
chartType = eChartType.Line;
}
var chart = worksheet.Workbook.Worksheets.AddChart($"{plotName} Chart", chartType);
var label = worksheet.Cells["A2:B2571"];
var values = worksheet.Cells["C2:C2571"];
chart.Chart.Series.Add(label, values);
chart.Chart.Legend.Position = eLegendPosition.Right;
Throwing all information into bottom area of chart and not in chart.
You should try something different like this:
//not chart type you should change it.
//change var to int and chart to double or float as you will wish
// again change var into int and worksheet is equal to ToString in C# then take off the string "" and change the : to referring after that you should just change 3 main things
// change chart to double or float suggesting float here because of the complex
// Chart is not good!!!! you can get the position in many different ways just set a .point = new Location (X,Y) then just set it twice and not once

How to make points more compact using fastpoint chart in

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..

How to get chart data points value with equal or less than to highlight those data

I'm looking to change my chart series data points if there is an error values. I want to set rule to highlight those data points like below. Please help to get below code working.
// Find first point with a Y2 value of equal or less than 10.
var dataPoint = Chart1.Series[1].Points.Where(x => x.YValues <= 10);
foreach (DataPoint dt in dataPoint)
{
dt.BorderDashStyle = ChartDashStyle.Dot;
dt.Color = Color.Red;
}
DataPoint.YValues is an array.
The YValues property is used to set the Y-values of data points.
Only one Y-value per point is required for all chart types except
bubble, candlestick and stock charts. These chart types require more
than one Y-value because one data point consists of multiple values.
For example, to plot one stock chart column, four values are required:
high, low, open and close values.
The YValues property returns an array of double values when used to
retrieve the Y-values.
Important The YValuesPerPoint property determines the maximum number
of Y-values that all data points in a Series can have. If you specify
more than the allowable number of Y-values, an exception will be
raised.
Unless you are using one of the above special ChartTypes you always will want to use the first element. So simply write:
var dataPoint = Chart1.Series[1].Points.Where(x => x.YValues[0] <= 10);
If you do use one of the three multiple Y-Values chart types you could, depending on the situation for example write this:
var dataPoint = Chart1.Series[1].Points.Where(x => x.YValues.Max() <= 10);
or this:
var dataPoint = Chart1.Series[1].Points.Where(x => x.YValues.Min() <= 10);

draw line chart from maximum point y axis

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..

Categories