Bar chart problem with a time valueformat X-axis

Thread is closed for posting
2 posts, 0 answers
  1. Oh Sangho
    Oh Sangho avatar
    4 posts
    Member since:
    Apr 2010

    Posted 11 Jun 2010 Link to this post

    Let me show a simple code below.


    .aspx

    <telerik:RadChart ID="RadChart3" runat="server" Width="1000" />


    .aspx.cs

    protected void Page_Load(object sender, EventArgs e)
        {

            DataTable chartdata = new DataTable();
            chartdata.Columns.Add("date", typeof(DateTime));
            chartdata.Columns.Add("value", typeof(double));

            
            List<string> dates = new List<string>();
            dates.Add("2010-06-01 02:44:35.753");
            dates.Add("2010-06-01 02:45:54.753");
            dates.Add("2010-06-01 02:47:13.543");
            dates.Add("2010-06-01 02:48:32.600");
            dates.Add("2010-06-01 02:49:51.730");
            dates.Add("2010-06-01 02:51:10.640");

            List<double> values = new List<double>();
            values.Add(120);
            values.Add(130);
            values.Add(140);
            values.Add(150);
            values.Add(160);
            values.Add(170);

            int k = 0;

            foreach (string strdate in dates)
            {
                DataRow cdr = chartdata.NewRow();
                cdr[0] = DateTime.Parse(strdate);
                cdr[1] = values[k];

                chartdata.Rows.Add(cdr);

                k++;           
            }

            ChartSeries series = RadChart3.CreateSeries("value", Color.DarkBlue, Color.Empty, ChartSeriesType.Bar);
                
            foreach (DataRowView drv in chartdata.DefaultView)
            {
                ChartSeriesItem item = new ChartSeriesItem();
                item.XValue = DateTime.Parse(drv["date"].ToString()).ToOADate();
                item.YValue = Math.Round(double.Parse(drv["value"].ToString()), 1);

                series.Items.Add(item);
            }

            RadChart3.AutoLayout = true;

            RadChart3.Series.Add(series);
            RadChart3.Appearance.BarWidthPercent = 1;

            RadChart3.PlotArea.XAxis.AutoScale = false;
            RadChart3.PlotArea.XAxis.Appearance.ValueFormat = Telerik.Charting.Styles.ChartValueFormat.ShortTime;
            RadChart3.PlotArea.XAxis.AddRange(DateTime.Parse("2010-06-01 02:42:00").ToOADate(), DateTime.Parse("2010-06-01 02:52:00").ToOADate(), (double)1 / 1440);

            RadChart3.PlotArea.YAxis.AutoScale = true;

    }





    And the chart is expected to show six bars.

    Actually, however, the chart shows only 2 bars, because they are overlapped.

    How can I solve this problem?


    Thank you.

    -Alex.



  2. Ves
    Admin
    Ves avatar
    2926 posts

    Posted 16 Jun 2010 Link to this post

    Hi Alex,

    There is a problem with the bars in DateTime scenarios, when the time span between the bars is relatively small (like minutes or seconds). Still, you can use Gantt chart in the very same manner and it will work in this scenario. You will only need to change ChartSeriesType.Bar to ChartSeriesType.Gantt.

    Sincerely,
    Ves
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top