none
How to set the x axis in different second in MSchart RRS feed

  • Question

  • I trying to plot the real time data in chart. My Chart1 x axis is time in second and y axis some data value .

    If my chart is showing all same second in x axis, but i want different ,which  mean each second. How to solve this ?

    Thursday, January 14, 2016 7:04 AM

Answers

  • Hi digitgeek,

    I see your code is VB. So I changed my C# code to VB.

    Based on your code, with some undefined parameters, your issue is not clear to me. Please
    refer to the following code to change your code. I also find some good
    materials related to MSChart, please take a look at https://social.msdn.microsoft.com/Forums/vstudio/en-US/5608a146-872a-4d53-9b2b-bc3c4d0c2f42/chart-controls-helpful-links?forum=MSWinWebChart


            Dim s As Series = New Series()
            s.ChartType = SeriesChartType.Line
     
            Dim d As DateTime = DateTime.Now
     
            s.Points.AddXY(d, 3)
            s.Points.AddXY(d.AddSeconds(1), 2)
            s.Points.AddXY(d.AddSeconds(2), 1)
            s.Points.AddXY(d.AddSeconds(3), 4)
     
            Chart1.Series.Clear()
            Chart1.Series.Add(s)
     
            Chart1.Series(0).XValueType = ChartValueType.DateTime
            Chart1.ChartAreas(0).AxisX.LabelStyle.Format = "HH:mm:ss"
            Chart1.ChartAreas(0).AxisX.Interval = 1
            Chart1.ChartAreas(0).AxisX.IntervalType = DateTimeIntervalType.Seconds
            Chart1.ChartAreas(0).AxisX.IntervalOffset = 1 

    >> I tried in below program ,for every 250 sample i want to Show the timesecond  in below the chart x axis label , but it no coming properly ..

    Given that you're specifying an Interval of 1, and a Maximum of 12:37:04(as my first reply posted) It makes sense that the the X labels shows fully. But if you use 250, it is too long so that can't be show in Chart area. You have to use each 1 to stand for 250 sample.

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Wednesday, January 20, 2016 7:45 AM

All replies

  • Hi digitgeek,

    >>If my chart is showing all same second in x axis, but i want different ,which  mean each second. How to solve this ?

    I assume you are developing in DataTime type, Do you mean increase  each second in X axis?  If yes, please try the following code,

      private void Form1_Load(object sender, EventArgs e)
            {
    
                var s = new Series();
                s.ChartType = SeriesChartType.Line;
    
                var d = DateTime.Now;
    
                s.Points.AddXY(d, 3);
                s.Points.AddXY(d.AddSeconds(1), 2);
                s.Points.AddXY(d.AddSeconds(2), 1);
                s.Points.AddXY(d.AddSeconds(3), 4);
    
                chart1.Series.Clear();
                chart1.Series.Add(s);
                chart1.Series[0].XValueType = ChartValueType.DateTime;
                chart1.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm:ss";
                chart1.ChartAreas[0].AxisX.Interval = 1;
                chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Seconds;
                chart1.ChartAreas[0].AxisX.IntervalOffset = 1;
    
            }

    Hope I understand you correctly, if not, please feel free to let me know.

    Have a nice day!

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, January 15, 2016 4:38 AM
  • Thank you kristin , Actually i have plot for every second 250 sample point in the chart. But you showed, 1 data per second . But in my  program 250 sample  per sec.

    i tried in below program ,for every 250 sample i want to Show the timesecond  in below the chart x axis label , but it no coming properly ..

    Dim samplesize As Integer = 250 Dim DataBuffer(samplesize-1 ) As Double Dim inc As integer Dim NextDatTimer As Date

    Dim Addsec As Integer =0

    private Sub Button1_Click( sender As System.Object ,e As System.EventArgs) handles Buton1.Click Dg_timer.Interval =4 // 4 milli Second Dg_timer.Start() End Sub private Sub Dg_timer_Tick(sender As System.Object , e As System.EventArgs)Handles Dg_timer.Tick Dim val As Double = NextDatTimer.Ticks/10000000.0 *4 buff = Cos (Val/1.0) * Cos (Val/11.9) shiftData(buff) NextDatTimer = Date.Now End Sub Private Sub ReadDataBUffer() For j As INteger = 0 to samplesize -1 if j =0 then Chart1.ChartSeries("Series1").Points.AddXY(d.AddSeconds(Addsec)DataBuffer(i)) Else Chart1.ChartSeries("Series1").Points.AddY(DataBuffer(i)) End If Addsec + =1 Next End Sub private Sub shiftData(Byval data As double ) DataBuffer(inc) = Data if unbound(DataBuffer) < inc ReadDataBUffer() inc= 0 Else inc +=1 End if End Sub private Sub Chart_initilize() Chart1.ChartSeries(0).AxisX.Minimum = 0 Chart1.ChartSeries(0).AxisX.Maximum = CDbl(Combox1.SelectedItem) * UBound(DataBUffer) Chart1.ChartSeries(0).AxisX.Interval = 250 Chart1.ChartSeries(0).AxisX.Labelstyle.Format = "HH:mm:ss" Chart1.ChartSeries(0).AxisX.INtervalOffsetType = DateTimeIntervalType.Seconds Chart1.Series[0].XValueTYpe = ChartValueType.DateTime End sub



    Monday, January 18, 2016 7:01 AM
  • Hi digitgeek,

    When I try to repro this issue based on your code, please take a look at Chart Class from MSDN.

    Chart1.ChartSeries(0).AxisX.Minimum = 0
      Chart1.ChartSeries(0).AxisX.Maximum = CDbl(Combox1.SelectedItem) * UBound(DataBUffer)
      Chart1.ChartSeries(0).AxisX.Interval = 250
      Chart1.ChartSeries(0).AxisX.Labelstyle.Format = "HH:mm:ss"
      Chart1.ChartSeries(0).AxisX.INtervalOffsetType = DateTimeIntervalType.Seconds 
       Chart1.Series[0].XValueTYpe = ChartValueType.DateTime
     

    There is no ChartSeries property, which control are you using?  I suspect that you are using the third-party control, if so, please redirect to the other officail website for better support.  Thanks for your understanding. 

    Have a nice day!  

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Kristin Xie Monday, January 18, 2016 8:09 AM
    Monday, January 18, 2016 8:08 AM
  • oh..  sorry ,  small changes in the code

    Chart1.ChartAreas(0).AxisX.Minimum = 0
      Chart1.ChartAreas().AxisX.Maximum = CDbl(Combox1.SelectedItem) * UBound(DataBUffer)
      Chart1.ChartAreas(0).AxisX.Interval = 250
      Chart1.ChartAreas(0).AxisX.Labelstyle.Format = "HH:mm:ss"
      Chart1.ChartAreas(0).AxisX.INtervalOffsetType = DateTimeIntervalType.Seconds 
       Chart1.Series[0].XValueTYpe = ChartValueType.DateTime


    • Edited by digitgeek Monday, January 18, 2016 1:08 PM
    Monday, January 18, 2016 8:32 AM
  • Hi digitgeek,

    I see your code is VB. So I changed my C# code to VB.

    Based on your code, with some undefined parameters, your issue is not clear to me. Please
    refer to the following code to change your code. I also find some good
    materials related to MSChart, please take a look at https://social.msdn.microsoft.com/Forums/vstudio/en-US/5608a146-872a-4d53-9b2b-bc3c4d0c2f42/chart-controls-helpful-links?forum=MSWinWebChart


            Dim s As Series = New Series()
            s.ChartType = SeriesChartType.Line
     
            Dim d As DateTime = DateTime.Now
     
            s.Points.AddXY(d, 3)
            s.Points.AddXY(d.AddSeconds(1), 2)
            s.Points.AddXY(d.AddSeconds(2), 1)
            s.Points.AddXY(d.AddSeconds(3), 4)
     
            Chart1.Series.Clear()
            Chart1.Series.Add(s)
     
            Chart1.Series(0).XValueType = ChartValueType.DateTime
            Chart1.ChartAreas(0).AxisX.LabelStyle.Format = "HH:mm:ss"
            Chart1.ChartAreas(0).AxisX.Interval = 1
            Chart1.ChartAreas(0).AxisX.IntervalType = DateTimeIntervalType.Seconds
            Chart1.ChartAreas(0).AxisX.IntervalOffset = 1 

    >> I tried in below program ,for every 250 sample i want to Show the timesecond  in below the chart x axis label , but it no coming properly ..

    Given that you're specifying an Interval of 1, and a Maximum of 12:37:04(as my first reply posted) It makes sense that the the X labels shows fully. But if you use 250, it is too long so that can't be show in Chart area. You have to use each 1 to stand for 250 sample.

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Wednesday, January 20, 2016 7:45 AM