2

My chart looks all jacked up. For one, there are too many labels along the x axis. For two, it is getting x axis info as a DateTime object. In this case, I would like to have the time of day shown.

So how can I make there be less labels and have the content of the labels be a time instead of a date?

http://i1120.photobucket.com/albums/l493/powerfulcrunch/chart.png

private void drawMinuteGraph(string data)
    {
        Chart chart = new Chart();
        Series series = new Series("default");
        series.ChartType = SeriesChartType.Line;
        chart.Series.Add(series);
        ChartArea chartArea = new ChartArea();
        chart.ChartAreas.Add(chartArea);
        Axis x = new Axis(chartArea, AxisName.X);
        x.LineWidth = 90;
        Axis y = new Axis(chartArea, AxisName.Y);
        Data[] _data = data.getHistory("History", data);
        List<DateTime> dates = new List<DateTime>();
        List<double> values = new List<double>();
        foreach (Data __data in _data)
        {
            dates.Add(__data.timestamp);
            values.Add(__data.value);
        }
        chart.Height = 150;
        chart.Width = 150;
        chart.Series["default"].Points.DataBindXY(dates, values);
        flowLayoutPanel.Controls.Add(chart);
    }
reuben
  • 3,360
  • 23
  • 28
user1472219
  • 199
  • 5
  • 9

1 Answers1

2

Use Axis.LabelStyle.Format property. Format Strings: http://msdn.microsoft.com/en-us/library/az4se3k1.aspx

Read this for how to set intervals

Custom Label Intervals

Quantbuff
  • 827
  • 7
  • 9
  • 1
    You are correct sir. Backed up here. http://stackoverflow.com/questions/5605852/microsoft-chart-controls-and-x-axis-time-scale-format Eventually got it working with chart.ChartAreas[0].AxisX.LabelStyle.Format ="HH:mm"; – user1472219 Jul 09 '12 at 04:39