This is a migrated thread and some comments may be shown as answers.

Need help on Multi Line Series chart

1 Answer 108 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ravi
Top achievements
Rank 1
Ravi asked on 08 Jun 2016, 07:43 PM

I am plotting WeekNumber of the year on X-axis, and Number of Requests of a particular school on to Y-axis of a Line Series.

Results of a Stored Procedure are assigned to a List of section-requests, by passing School ID, and a date range.

The output of Stored procedure gives: Number of Requests per week, Created Date, Week Number (of the Year), School Name.

Code calls stored procedure 5 times, and stores the results in 5 individual Lists. Code loops through an array of 5 Lists (section-requests) .

By using the LineSeries, AxisItem, and CategorySeriesItem , I have created a Multi-Line chart. 

My issues are:
(1) Once the first List plots on the first LineChart, because of the looping as individual Lists, the Week Number of the second List is starting from where the Week Number of the first List ended.  Is there a way that I can group all the Lists with the LineSeries, and plot only one set of Week Numbers (X axis) and related LineSeries (Y axis) for each individual school?  Please take a look at the Line chart in the attached file

(2) If there is no section-request in a particular week, I need logic to treat “Number of Requests per week” as zero.

For Loop Code:

for (int i = 0; i < arrMasterList.Length; i++)
{
    int intCount = arrMasterList[i].Count;

    foreach (var sectionRequest in arrMasterList[i])
    {
        intSecReqs = sectionRequest.NumberOfRequestsPerWeek;

        if (intSecReqs >= 0)
        {
            AxisItem item = new AxisItem();
            item.LabelText = "Wk: " + sectionRequest.WeekNumber;
            LineChart.PlotArea.XAxis.Items.Add(item);

            CategorySeriesItem categorySeriesItem = new CategorySeriesItem();
            categorySeriesItem.Y = intSecReqs;
            arrLineSeries[i].SeriesItems.Add(categorySeriesItem);
            lstSecReqs.Add(intSecReqs);
        }

        LineChart.PlotArea.Series.Add(arrLineSeries[i]);
      }
   }

   intMaxValueReqs = lstSecReqs.Max();

   LineChart.PlotArea.YAxis.MinValue = 0;
   LineChart.PlotArea.YAxis.MaxValue = intMaxValueReqs + 10;
   LineChart.PlotArea.YAxis.MinorGridLines.Color = Color.White;
   LineChart.PlotArea.XAxis.MajorGridLines.Color = Color.White; 
   LineChart.PlotArea.XAxis.TitleAppearance.Text = "Week number";


1 Answer, 1 is accepted

Sort by
0
Danail Vasilev
Telerik team
answered on 13 Jun 2016, 12:47 PM
Hi Ravi,

Basically, you have two options:
     1) Use category series (i.e., line series). This means each y-value will be aligned over the corresponding x-axis category. In that case you should create null y-values for missing x-axis categories, so that the y-values can be properly aligned.
     2) Use numeric series (i.e., scatterline series). In that case you can set the x for each y from the series item. This may be the easier approach.

You can also use binding for both approaches.

Regards,
Danail Vasilev
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
General Discussions
Asked by
Ravi
Top achievements
Rank 1
Answers by
Danail Vasilev
Telerik team
Share this question
or