question

MichalBroek-6206 avatar image
0 Votes"
MichalBroek-6206 asked MichalBroek-6206 edited

Value on x axis spline chart

Hello dear colleagues,

i would like to aks for support for my application in C# where are use spline chart. Chart is real time and i add data from serial port. In visualisation i would like to show value on x axis in value like 1, 2 ,3 ..... n. But in chart i see on x axis values in number with one decimal place and no on the primary grid. Problem you can see in attached image. Please is there anybody who can help me to solve this "problem"?

Thanks and have a nice day.

Michal

141892-obrazek.png


dotnet-csharp
obrazek.png (23.2 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@MichalBroek-6206, Could you provide some code with me about how does the chart create?

0 Votes 0 ·

1 Answer

MichalBroek-6206 avatar image
0 Votes"
MichalBroek-6206 answered MichalBroek-6206 edited

@JackJJun-MSFT, here is my code. In chart on axis X are number of sample and on axis Y value of temperature.

I have found out where is a problem. The count of points on axis X must be ODD number (in my code variable "pocetVzorkuNaOseXVsechnyGrafy"). I had even and it was wrong.


  // Custom properties of chart
    
                 grafTeplotaVeStupnichCelsia.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;
                 grafTeplotaVeStupnichCelsia.ChartAreas[0].AxisX.Title = "Cislo vzorku";
                 grafTeplotaVeStupnichCelsia.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
                 grafTeplotaVeStupnichCelsia.ChartAreas[0].AxisX.MajorGrid.Interval = 5;
                 grafTeplotaVeStupnichCelsia.ChartAreas[0].AxisY.Interval = 20;
                 grafTeplotaVeStupnichCelsia.ChartAreas[0].AxisY.Title = "Teplota t [°C]";
                 grafTeplotaVeStupnichCelsia.ChartAreas[0].AxisY.LabelStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", 8);
                 grafTeplotaVeStupnichCelsia.ChartAreas[0].AxisX.LabelStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", 8);
    
                 Title title = new Title();
                 title.Font = new System.Drawing.Font("Arial", 10);
                 title.Text = "Prubeh teploty";
                 grafTeplotaVeStupnichCelsia.Titles.Add(title);
                 grafTeplotaVeStupnichCelsia.Series[0].IsVisibleInLegend = false;
    
                 ChBx_zobrazHodnotyRadyTeplota.Checked = true;
                 grafTeplotaVeStupnichCelsia.Series[0].IsValueShownAsLabel = true;
    
 // Add data point to chart
                 grafTeplotaVeStupnichCelsia.Series[0].Points.AddXY(indexSebranehoVzorku, listTeplotaCelsius[indexSebranehoVzorku]);
    
 // Set up maximum points on axis X
                  if (grafTeplotaVeStupnichCelsia.Series[0].Points.Count > pocetVzorkuNaOseXVsechnyGrafy)
                     grafTeplotaVeStupnichCelsia.Series[0].Points.RemoveAt(0);
    
                     grafTeplotaVeStupnichCelsia.ChartAreas[0].AxisX.Minimum = grafTeplotaVeStupnichCelsia.Series[0].Points[0].XValue;
                     grafTeplotaVeStupnichCelsia.ChartAreas[0].AxisX.Maximum = indexSebranehoVzorku;


143589-obrazek.png



obrazek.png (16.1 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.