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
WCF Data to XamWebChart and Date Column to the X-axis ?
posted

I am using the trial version of Silverlight DataVisualization chart and I would like to use data from a web service as the input to this chart. Another thing that I would like to do is add the date from the data retrieved to the X-axis. Following is the code I am using

 

  1. public class PageViewData
  2.     {
  3.         public DateTime _xAxisValue { get; set; }
  4.         public int _yAxisValue { get; set; }
  5.     }
  6.  
  7.     public partial class MainPage : UserControl
  8.     {
  9.         private ChartDataSVC.ChartDataSvcClient _chartDataClient;
  10.  
  11.        
  12.         public MainPage()
  13.         {
  14.             InitializeComponent();
  15.  
  16.             _chartDataClient = new ChartDataSvcClient();
  17.             _chartDataClient.GetPageViewDataCompleted += _PageViewDataCompleted;
  18.  
  19.         }
  20.  
  21.         private void _PageViewDataCompleted(object sender, ChartDataSVC.GetPageViewDataCompletedEventArgs e)
  22.         {
  23.             List<SquarePoolView> chartData = new List<SquarePoolView>();
  24.             if (e.Cancelled == false)
  25.             {
  26.                 //chartData = List<SquarePoolView> e.Result;
  27.             }
  28.  
  29.         }
  30.  
  31.  
  32.         private void UserControl_Loaded(object sender, RoutedEventArgs e)
  33.         {
  34.            
  35.  
  36.  
  37.  
  38.             List<PageViewData> chartData = new List<PageViewData>();
  39.             Random random = new Random();
  40.  
  41.             int yValue = 100;
  42.  
  43.             DataPoint[] dataPoints = new DataPoint[10];
  44.             Series series = new Series();
  45.  
  46.             for (int i = 0; i < 10; i++)
  47.             {
  48.                 yValue = yValue*(+ 2);
  49.                 chartData.Add(new PageViewData() { _xAxisValue = DateTime.Now.Date.AddDays(-(+ 1)), _yAxisValue = yValue});
  50.  
  51.                
  52.                 //dataPoints[i].ChartParameters.Add(new ChartParameter(ChartParameterType.ValueX, DateTime.Now.Date.AddDays(-(i + 1))));
  53.                 //dataPoints[i].ChartParameters.Add(new ChartParameter(ChartParameterType.ValueY, yValue));
  54.                 //series.DataPoints.Add(dataPoints[i]);
  55.             }
  56.             series.AxisX = "Date";
  57.             series.AxisY = "Views";
  58.             series.ChartType = ChartType.Line;
  59.             series.DataPointColor = DataPointColor.Same;
  60.             series.DataSource = chartData;
  61.            
  62.             series.DataMapping = "ValueX=_xAxisValue;ValueY=_yAxisValue";
  63.  
  64.             theChart.Series.Add(series);
  65.         }
  66.  
  67.     }

    What is it that I am doing wrong? All I can see is the X-axis is set to1 through 10 and on Y-axis I see nothing. And this chart does not show the grid or the zoom feature on Google Chrome but shows the grid and zooming features in FF.

Parents Reply Children