0

I have data with date against data so I wanted to plot LineSeries of it. I am using following code I wanted to put Date on X-axis and bind my data with my dates.

public class LineChart
{
    public PlotModel MyModel { get; set; }

    DateTime from_date, end_date;

    public LineChart()
    {
        var plotModel = new PlotModel { 
            Title="Multiview"
        };

        var xAxis = new DateTimeAxis {
         StringFormat="MM/DD/yyyy"  
        };

        var linearAxis = new LinearAxis();

        plotModel.Axes.Add(xAxis);
        plotModel.Axes.Add(linearAxis);

        var series1 = new LineSeries { 
            StrokeThickness=3,
            MarkerType=MarkerType.Cross,
            MarkerStroke=OxyColors.Aqua,
            MarkerSize=4,
            MarkerStrokeThickness=1,
            DataFieldX="Date",
            DataFieldY="Value",
            Smooth=true
        };

        series1.Points.Add(new DataPoint(1.2,4.5));
        series1.Points.Add(new DataPoint(2.2, 5.8));
        series1.Points.Add(new DataPoint(4.4, 8.7));

        plotModel.Series.Add(series1);

        this.MyModel = plotModel;
    }

Since DataPoint accepts only (double,double) data type, then How to I plot Date against my date??

Rohit
  • 2,646
  • 6
  • 27
  • 52

1 Answers1

0

Use the DateTimeAxis.ToDouble or DateTimeAxis.CreateDataPoint methods (the last one will create points you can add directly to e.g. a LineSeries).

nuclear sweet
  • 1,079
  • 10
  • 27
  • On Axis it is showing incorrect date... I have used, `series1.Points.Add(new DataPoint(DateTimeAxis.ToDouble(DateTime.Now),4));` – Rohit Nov 07 '14 at 03:49