Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
60
Howt to show X Axis Label in DateTime format?
posted

Hello

 

I am trying to show X Axis Label values in datetime format like "2010-06-23 15:00" and I want to set step for X Axis as one hour.

My entity class has DateTime type property for X Axis. How to to this?

Following is my code :

private void SetChartStyle()

        {

            Axis xAxis = new Axis();

            xAxis.AxisType = AxisType.PrimaryX;

            xAxis.AutoRange = false;

            xAxis.Label.Format = "{mm/dd/yy}";

            xAxis.Label.Angle = 45;

            webChart.Axes.Add(xAxis);

        }

 

 

 

void server_GetGraphDataCompleted(object sender, GetGraphDataCompletedEventArgs e)

        {

            List<GraphEntity> result = e.Result;

            Series seriesBT = new Series();

            seriesBT.Label = "BT"; 

            seriesBT.ChartType = ChartType.Line;

            seriesBT.DataMapping = "Label=Xcolumn;Value=Ycolumn";

            seriesBT.DataSource = result;

            webChart.Series.Add(seriesBT);

       }

 

 

public class GraphEntity

{

     public DateTime  Xcolumn { get; set; }

     public Double Ycolumn { get; set; }

}

 

Furthermore, in order to set Minimum/Maximum Value in datetime format for X Axis, how to do it?

 

Thanks in Advance

Kwon

 

Parents
No Data
Reply
  • 816
    Suggested Answer
    posted

    I think this ScatterLine chart example should prove useful for you.

    XAML:

        <Grid x:Name="LayoutRoot" Background="White" Loaded="LayoutRoot_Loaded">
            <ig:XamWebChart Name="chart1">
            </ig:XamWebChart>
        </Grid>
    

    C#:

            private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
            {
                DataPoint d = new DataPoint();
                d.ChartParameters.Add(new ChartParameter(ChartParameterType.ValueX, new DateTime(2010, 7, 6)));
                d.ChartParameters.Add(new ChartParameter(ChartParameterType.ValueY, 10));
    
                DataPoint d1 = new DataPoint();
                d1.ChartParameters.Add(new ChartParameter(ChartParameterType.ValueX, new DateTime(2010, 7, 7)));
                d1.ChartParameters.Add(new ChartParameter(ChartParameterType.ValueY, 20));
    
                DataPoint d2 = new DataPoint();
                d2.ChartParameters.Add(new ChartParameter(ChartParameterType.ValueX, new DateTime(2010, 7, 8)));
                d2.ChartParameters.Add(new ChartParameter(ChartParameterType.ValueY, 30));
    
                Series s1 = new Series();
                s1.ChartType = ChartType.ScatterLine;
                s1.DataPoints.Add(d);
                s1.DataPoints.Add(d1);
                s1.DataPoints.Add(d2);
                this.chart1.Series.Add(s1);
    
                Axis primXaxis = new Axis();
                primXaxis.AxisType = AxisType.PrimaryX;
                primXaxis.Label.Format = "{0:g}";
                primXaxis.AutoRange = false;
                primXaxis.Minimum = new DateTime(2010, 7, 5, 12, 0, 0).ToOADate();
                primXaxis.Maximum = new DateTime(2010, 7, 10, 12, 0, 0).ToOADate();
                primXaxis.Unit = new DateTime(1999,1,1,6,0,0).ToOADate() - new DateTime(1999,1,1,0,0,0).ToOADate(); // 6-hour interval
                this.chart1.Axes.Add(primXaxis);
            }
    

    See also this MSDN article:

    Standard Date and Time Format Strings

Children
No Data