I have two columns in my datagridview and I want my first column to be the X axis while the second column to be the Y axis in my chart.
it is suppose to create a line graph.
Usually there is no difference between line, point or bar charttypes; simply loop over the rows to add the DataPoints!
But in your case the x-values (timestampdata) are all the same! For Line and Points charttypes this will mean that all Points get lumped onto the same spot. Bar charts indeed wouldn't do that.
If you can't (or don't want to) get good data you need to set :
yourSeries1.IsXValueIndexed = true;
Then all DataPoints will be lined up, ignoring the x-values.
Related
Apologies for not able to find a more suitable title for my issue here. I am using MS Chart control in my project to plot real-time values from a source that generates 4 values per second. X axis is time at which the value is generated and the Y axis the value itself. I am dynamically adding a new series for each variable. All the variables are manually added by the user one-by-one and then a series will be created for it.
Basic part seems to be working except the chart is plotting values from different series at different time even though the values are generated at same time. Following image shows the exact issue:
As you can see, the list in bottom is a list of values I am plotting. It shows values and the time they are generated at (hh:mm:ss.ms)
When I plot these values, which is shown in the chart area, this is what I get. See the location of the latest values (marked by red arrows) for all the series. The latest value is at different time even though they all are generated at the same time. Every series seem to have a separate X axis. I expected the latest Y values should be plotted at the same X value and that should be shown at the extreme right of the chart. More like the bottom most series is being shown. That is the very first series created. Every time only the series that is created first works fine and the following series lags for some reason.
Chart, share X axis between different series looks like similar issue to mine but is not answered.
Chart Multiple series different length generate duplicate x axis seems to be the exact issue I am having but the difference is - I am plotting a real-time graph. I can't loop through every series after adding a new data point to mark whether a point is empty or not. That will be a lot of overhead. Some Googling suggested use of InsertEmptyPoints() to every series to match all the X axis. MS Chart sample code also explains using this method but I am not sure where/when to use this method. If I use it after creating a series but before adding a data point - the code crashes. I have tried something like this:
_chart.Series.Add(series);
_chart.DataManipulator.InsertEmptyPoints(250, IntervalType.Milliseconds, name);
Am I doing something wrong here? Thanks for any help offered.
I got this working by adding empty points. I filled every series with max possible data points to begin with. Say I want to show 100 data points in every series before I start deleting the oldest (Points[0]) data point so that my chart will look like it's moving from right to left. In that case I will add 100 empty points while creating every series using:
for (int i = 0; i < 100; i++)
{
series.Points.AddXY(i.ToString(), double.NaN);
series.Points[i].AxisLabel = " ";
}
Then, while adding real data just do it normal way:
_chart.Series[index].Points.AddXY(time, YValue);
// delete more than max. points.
if (_chart.Series[index].Points.Count > MaxTrendPoints - 10) // -10 is adjustment. Got it by trial and error.
_chart.Series[index].Points.RemoveAt(0);
I've got two chart types sharing one chart area. One of the charts is a smooth area chart (three of this type are generated but only one is shown in the designer), the other is a column chart.
The purpose of the column chart is to indicate where some limits are located on the smooth area chart. The charts are created well except that the smooth area chart has gaps where the limit lines show up.
How do I get rid of the gaps that are occurring? The following images are print screens of my issue.
Thanks
Turns out that the column chart data is included in the C# list that I'm using as a data source for these charts. So, when making the smooth area graphs it is using those red lines values as a data point, causing a gap because they're y value is set to 0. There is no gap, just a 0 value.
The column chart y values are actually a different parameter with a random name but using the same dataset, since the smooth area chart doesn't have that value set, they are effectively 0, so you don't see them show up as columns.
The real problem is that I basically need to show data conditionally, or get two datasets in one chart.
I pass a dataset to my report, which renders a line chart showing a sprint burn down chart. One of the fiends in the dataset is 'PeriodType', which can be either 'Planning, 'Burning' or 'Retrospective'.
The chart shows dates along x axis, and the y axis holds hours.
What I would like to do, is grey the background, where the x axis has a value that is not a 'Burning' period. So the object that is used to create the chart, as mentioned, has a type field I can use.
Is there a way to change the background colour of the x 'columns' based on the flag? Some sort of conditional background colouring? I have searched, but can't seem to find such a handy thing.
Yes, that is possible.
Open the Properties pane, in the BackgroundColor or Color (whichever is relevant) property of the chart, enter an IFF statement like:
=IIF(Str(Fields!PeriodType.Value) <> "Burning", "Gray", "SomeOtherColor")
Hope that helps
I have a chart with 4 series. Each series is added at different times, depending on what is switched on/off of the app features. All series have on the x axis:
DateTime.Now.ToString("mm:ss")
so I thought that at any time the series data are available, they will be added to the chart at that time that happens on x axis. Looks like is not like that. This chart shows a blue line and a red line. The blue line started first then after few seconds I checked checkBox2 which activate the red line, that happened exactly at 27:38 (where you can see a small drop on the blue line). I do not understand why the red line starts at the far left of the chart and not at the time that was triggered (27:38).
This is my code:
string reqTemp = textBox9.Text;
textBox2.Text = avTemp.ToString("F");
this.chart1.Series["Actual Temperature"].Points.AddXY(DateTime.Now.ToString("mm:ss"), avTemp);
if (checkBox2.Checked == true)
{
this.chart1.Series["Requested Temperature"].Points.AddXY(DateTime.Now.ToString("mm:ss"), reqTemp);
}
How can I have the series added after the first one was already running starting at the time they are switched on? Basically all series sharing the same x axis.
All series have on the x axis:
DateTime.Now.ToString("mm:ss")
I read this as: All your X-Values are added as formatted strings; this is usually a bad thing, as by doing so the X-Values have become all 0s, read: meaningless.
If you want to preserve the DateTime values you need to add the DataPoints with valid X-Values!
So you should add them as AddXY(yourDateTimeXValue, yourYValue); and set the Format as
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "mm:ss";
To explain my question I drew an image, here it is:
So I have a Chart that has a bar graph and a line chart, 2 in 1. I am trying to displaly it in asp.net just the way i drew it on here. This means the A box on the image has a set of values which reflect the line graph, and C box on the image has a set of values that define the bar graph values.
What I want to ask is how do I set two different sets of values on a single chart. I know I can use series to draw multiple graphs and by having series defined as different types I can change if its a bar graph or a ilne chart, however I don't know how to add 2 range of values on the side.
As for the the box B, what I wish to ask is how do I set these values so that they are showing different dates, I was able to do it using a line of code shown bellow, however that line of code sets every value to same, and I need them to reflect different values such as range of dates in this example on the image.
Code that I tried is: Chart1.Series["Series1"].AxisLabel = "Test";
Help is most appreciated!
Cheers!
Ok so i'm going to leave this question up for those that come into similar problem.
This is how you set column A and column c
Chart1.Series[0].YAxisType = AxisType.Primary;
Chart1.Series[1].YAxisType = AxisType.Secondary;
Chart1.ChartAreas[0].AxisY.Maximum = 500;
Chart1.ChartAreas[0].AxisY2.Maximum = 7000;
Your grid lines might get messed up so if you want to disable them use
Chart1.ChartAreas[0].AxisY2.MajorGrid.Enabled = false;
And just as a bonus if you want to set intervals on each Y axis you can do that with
Chart1.ChartAreas[0].AxisY.Interval = 50;
I still haven't figured out how to do part B that I mentioned, so if you know the answer then please share.
Cheers!