예제 #1
0
 private void DrawBarGraph()
 {
     dt = CreateDataTable();
     ChartBar.DataSource = dt;
     ChartBar.Series[0].YValueMembers = "Count";
     ChartBar.Series[1].YValueMembers = "Costs";
     ChartBar.Series[0].XValueMember  = "CategoryName";
     ChartBar.DataBind();
 }
예제 #2
0
 protected void ParseResponseSection(ChartBar chartBar)
 {
     // check the order with the documentation, also maybe some casting is needed because other types are in the byte[]
     chartBar.close     = _rdr.ReadSingle();
     chartBar.high      = _rdr.ReadSingle();
     chartBar.low       = _rdr.ReadSingle();
     chartBar.open      = _rdr.ReadSingle();
     chartBar.timestamp = _rdr.ReadInt64();
 }
예제 #3
0
 private void DrawBarGraph()
 {
     dt = CreateDataTable();
     ChartBar.DataSource = dt;
     ChartBar.Series[0].YValueMembers = "Count";
     ChartBar.Series[1].YValueMembers = "GrossSales";
     ChartBar.Series[2].YValueMembers = "Profits";
     ChartBar.Series[1].XValueMember  = "ParentCategoryName";
     ChartBar.DataBind();
 }
예제 #4
0
    public void AddChartBar()
    {
        ChartBar bar = (ChartBar)Instantiate(chartBarPrefab, chartPositiveRegion.transform);

        bar.GetComponent <RectTransform>().sizeDelta = new Vector2(BAR_WIDTH, 0f);
        bar.GetComponent <Image>().color             = barColorPositive;
        bar = (ChartBar)Instantiate(chartBarPrefab, chartNegativeRegion.transform);
        bar.GetComponent <RectTransform>().sizeDelta = new Vector2(BAR_WIDTH, 0f);
        bar.GetComponent <Image>().color             = barColorNegative;
    }
예제 #5
0
        private void GenerateBarsInChart()
        {
            LengthForXAxis = 1;                                                                                                                    //reset variable to 1 if it is not 1 (which is the standard offset from the Y-Axis to not overlap, if the chart was already calculated before, this will not contain zero so this is necassary)
            double SpaceAvailablePerBar = ((double)ChartWidth - ChartSpaceOffsetLeft - ChartSpaceOffsetRight) / (double)DataList.DataPoints.Count; // the 2 here should be "assignable"

            BarHeightModifier = (ChartAvailableSpaceY) / (HigestTickMarkValue - LowestTickMarkValue);

            // space available per bar gives us the amount of pixels we are allowed to spend, then we add in emtpy spaces with BarGapModifier
            // if anything other than a number between 0 and 1, don't show any gaps between bars
            if (AddWhiteSpacePerBar < 0 || AddWhiteSpacePerBar > 1)
            {
                AddWhiteSpacePerBar = 0;
            }


            double BarWidthWhitespace = SpaceAvailablePerBar * AddWhiteSpacePerBar; //calculate whitespace per bar

            BarWidth = SpaceAvailablePerBar - BarWidthWhitespace;                   //leftover amounts go to the bar itself



            for (int LoopCounter = 0; LoopCounter < DataList.DataPoints.Count; LoopCounter++)//using loopcounter since we need to know on which bar we are for positioning
            {
                //from this part its going to be interesting.. we need to accomodate for a waterfall, not individual values...
                var CurrentBar = new ChartBar();
                CurrentBar.Name = "BarInChart"; //Identifier for collection

                if (!DataList.TargetLine.Equals(null))
                {
                    if (DataList.DataPoints[LoopCounter].Value < DataList.TargetLine)
                    {
                        CurrentBar.Fill = DataList.WorseThanTargetColor;
                    }
                    else
                    {
                        CurrentBar.Fill = DataList.BetterThanTargetColor;
                    }
                }
                else
                {
                    CurrentBar.Fill = DataList.Color;
                }



                CurrentBar.Width = BarWidth; //set the bar width to represent the data


                // calculate the 0 y-axis value of the chart in pixels



                // so now we need to, at least, also have the value where we ended up from the previous bar, otherwise this will not make much sense
                // Still I want to keep the data input the same, so we need to modify this code "a bit"



                if (LowestTickMarkValue == 0) //
                {
                    CurrentBar.Height    = BarHeightModifier * DataList.DataPoints[LoopCounter].Value;
                    CurrentBar.YPosition = (ChartHeight - ChartSpaceOffsetBottom) - DataList.DataPoints[LoopCounter].Value * BarHeightModifier;
                }
                else if (MinDataValue >= 0) // normal chart starting from above 0
                {
                    CurrentBar.Height    = BarHeightModifier * (DataList.DataPoints[LoopCounter].Value - LowestTickMarkValue);
                    CurrentBar.YPosition = (ChartHeight - ChartSpaceOffsetBottom) - (DataList.DataPoints[LoopCounter].Value - LowestTickMarkValue) * BarHeightModifier;
                }
                else //chart that has y=0 somewhere in the middle
                {
                    if (DataList.DataPoints[LoopCounter].Value > 0)
                    {
                        CurrentBar.Height    = BarHeightModifier * (DataList.DataPoints[LoopCounter].Value);
                        CurrentBar.YPosition = -YAxisZeroValueOffset + (ChartHeight - ChartSpaceOffsetBottom) - (DataList.DataPoints[LoopCounter].Value) * BarHeightModifier;
                    }
                    else
                    {
                        CurrentBar.Height    = BarHeightModifier * (-DataList.DataPoints[LoopCounter].Value);
                        CurrentBar.YPosition = -YAxisZeroValueOffset + (ChartHeight - ChartSpaceOffsetBottom);
                    }
                }



                //now we need to position the bar correctly on the graph, how many pixels to the right?
                // 3 is the standard offset to not hit the Y-Axis
                // BarWidth is the width of the bar itself, barWidthWhitespace is the gaps between the bars
                // the last bit ensures the first bar also has half a whitespace in front of it

                // add a bit of whitespace before the first bar, makes it look better in the chart
                if (LoopCounter == 0)
                {
                    LengthForXAxis += BarWidthWhitespace / 2 + ChartSpaceOffsetLeft;
                }


                CurrentBar.XPosition = LengthForXAxis;
                //Canvas.SetLeft(CurrentBar, LengthForXAxis);


                ChartNodesCollection.Add(CurrentBar);

                //ShapeCollection.Children.Add(CurrentBar);

                // if the datapoint has a name, it should display below the bar



                if (!string.IsNullOrWhiteSpace(DataList.DataPoints[LoopCounter].Name))
                {
                    var BarName = new ChartText();
                    BarName.Name = "BarInChartNameBox";

                    BarName.Text = DataList.DataPoints[LoopCounter].Name;

                    BarName.YPosition = ChartHeight - ChartSpaceOffsetBottom;
                    BarName.XPosition = LengthForXAxis + SpaceAvailablePerBar / 2;

                    BarName.Width = 200;


                    //Canvas.SetTop(BarName, ChartHeight-150);
                    //Canvas.SetLeft(BarName, LengthForXAxis+SpaceAvailablePerBar/2);

                    BarName.RenderTransform = new RotateTransform(30);

                    ChartNodesCollection.Add(BarName);

                    //ShapeCollection.Children.Add(BarName);
                }

                LengthForXAxis += (BarWidth) + (BarWidthWhitespace); //prepare for adding the next bar in the chart :)
            }
        }
예제 #6
0
 public Result(LinkedList<Process> list, int numberOfProcesses) : this()
 {
     double avwt = 0;
     var itrProcess = list.First;
     while (itrProcess != null)
     {
         var process = itrProcess.Value;
         double lastMark;
         LinkedListNode<TimeInfo> itrTime;
         if (process == list.First())
         {
             if (process.ArrivalTime > 0)
             {
                 StackPanel.Children.Add(new TimeMarker(0));
                 var chartBarIdle = new ChartBar("Idle", process.ArrivalTime)
                 { VerticalAlignment = VerticalAlignment.Top };
                 StackPanel.Children.Add(chartBarIdle);
             }
             StackPanel.Children.Add(new TimeMarker(process.ArrivalTime));
         }
         else
         {
             lastMark = double.Parse(StackPanel.Children.OfType<TimeMarker>().Last().Time.Content.ToString());
             if (Math.Abs(process.ArrivalTime + 1) < double.Epsilon)
             {
                 process.ArrivalTime = lastMark;
                 itrTime = _timeInfos.First;
                 while (itrTime != null)
                 {
                     if (itrTime.Value.ProccessName != process.Name)
                     {
                         itrTime = itrTime.Next;
                         continue;
                     }
                     avwt += process.ArrivalTime - itrTime.Value.ProcessLastTime;
                     break;
                 }
             }
             else if (process.ArrivalTime > lastMark)
             {
                 var chartBarIdle = new ChartBar("Idle", process.ArrivalTime - lastMark)
                 { VerticalAlignment = VerticalAlignment.Top };
                 StackPanel.Children.Add(chartBarIdle);
                 StackPanel.Children.Add(new TimeMarker(process.ArrivalTime));
             }
             else
             {
                 avwt += lastMark - process.ArrivalTime;
             }
         }
         var chartBar = new ChartBar(process.Name, Math.Round(process.BurstTime, 2))
         { VerticalAlignment = VerticalAlignment.Top};
         StackPanel.Children.Add(chartBar);
         lastMark = double.Parse(StackPanel.Children.OfType<TimeMarker>().Last().Time.Content.ToString());
         StackPanel.Children.Add(new TimeMarker(lastMark + process.BurstTime));
         var flag = true;
         itrTime = _timeInfos.First;
         while (itrTime != null)
         {
             if (itrTime.Value.ProccessName != process.Name)
             {
                 itrTime = itrTime.Next;
                 continue;
             }
             itrTime.Value.ProcessLastTime = lastMark + process.BurstTime;
             flag = false;
             break;
         }
         if (flag)
             _timeInfos.AddLast(new TimeInfo(process.Name, lastMark + process.BurstTime));
         itrProcess = itrProcess.Next;
     }
     Avwt.Content = "Average waiting time = " + avwt / numberOfProcesses;
 }
예제 #7
0
        private void GenerateBarsInChart()
        {
            LengthForXAxis = 1;                                                                           //reset variable to zero if it is not 1 (which is the standard offset from the Y-Axis to not overlap)
            double SpaceAvailablePerBar = ((double)ChartWidth - 200) / (double)DataList.DataPoints.Count; // the 2 here should be "assignable"

            BarHeightModifier = (ChartHeight - 250) / (HigestTickMarkValue - LowestTickMarkValue);

            // space available per bar gives us the amount of pixels we are allowed to spend, then we add in emtpy spaces with BarGapModifier
            // if anything other than a number between 0 and 1, don't show any gaps between bars
            if (AddWhiteSpacePerBar < 0 || AddWhiteSpacePerBar > 1)
            {
                AddWhiteSpacePerBar = 0;
            }


            double BarWidthWhitespace = SpaceAvailablePerBar * AddWhiteSpacePerBar; //calculate whitespace per bar

            BarWidth = SpaceAvailablePerBar - BarWidthWhitespace;                   //leftover amounts go to the bar itself



            for (int LoopCounter = 0; LoopCounter < DataList.DataPoints.Count; LoopCounter++)//using loopcounter since we need to know on which bar we are for positioning
            {
                var CurrentBar = new ChartBar();
                CurrentBar.Name = "BarInChart"; //Identifier for canvas collection

                if (!DataList.TargetLine.Equals(null))
                {
                    if (DataList.DataPoints[LoopCounter].Value < DataList.TargetLine)
                    {
                        CurrentBar.Fill = DataList.WorseThanTargetColor;
                    }
                    else
                    {
                        CurrentBar.Fill = DataList.BetterThanTargetColor;
                    }
                }
                else
                {
                    CurrentBar.Fill = DataList.Color;
                }



                CurrentBar.Width = BarWidth; //set the bar width to represent the data

                if (ForceYStartAtZero)
                {
                    CurrentBar.Height    = BarHeightModifier * DataList.DataPoints[LoopCounter].Value;
                    CurrentBar.YPosition = (ChartHeight - 150) - DataList.DataPoints[LoopCounter].Value * BarHeightModifier - 2;
                    //Canvas.SetTop(CurrentBar, (ChartHeight-150) - DataList.DataPoints[LoopCounter].Value * BarHeightModifier - 2);
                }
                else
                {
                    CurrentBar.Height    = BarHeightModifier * (DataList.DataPoints[LoopCounter].Value - LowestTickMarkValue);
                    CurrentBar.YPosition = (ChartHeight - 150) - (DataList.DataPoints[LoopCounter].Value - LowestTickMarkValue) * BarHeightModifier - 2;
                    //Canvas.SetTop(CurrentBar, (ChartHeight-150) - (DataList.DataPoints[LoopCounter].Value - LowestTickMarkValue) * BarHeightModifier - 2);
                }



                //now we need to position the bar correctly on the graph, how many pixels to the right?
                // 3 is the standard offset to not hit the Y-Axis
                // BarWidth is the width of the bar itself, barWidthWhitespace is the gaps between the bars
                // the last bit ensures the first bar also has half a whitespace in front of it

                // add a bit of whitespace before the first bar, makes it look better in the chart
                if (LoopCounter == 0)
                {
                    LengthForXAxis += BarWidthWhitespace / 2 + 100;
                }


                CurrentBar.XPosition = LengthForXAxis;
                //Canvas.SetLeft(CurrentBar, LengthForXAxis);


                ChartNodesCollection.Add(CurrentBar);

                //ShapeCollection.Children.Add(CurrentBar);

                // if the datapoint has a name, it should display below the bar



                if (!string.IsNullOrWhiteSpace(DataList.DataPoints[LoopCounter].Name))
                {
                    var BarName = new ChartText();
                    BarName.Name = "BarInChartNameBox";

                    BarName.Text = DataList.DataPoints[LoopCounter].Name;

                    BarName.YPosition = ChartHeight - 150;
                    BarName.XPosition = LengthForXAxis + SpaceAvailablePerBar / 2;

                    BarName.Width = 200;


                    //Canvas.SetTop(BarName, ChartHeight-150);
                    //Canvas.SetLeft(BarName, LengthForXAxis+SpaceAvailablePerBar/2);

                    BarName.RenderTransform = new RotateTransform(30);

                    ChartNodesCollection.Add(BarName);

                    //ShapeCollection.Children.Add(BarName);
                }

                LengthForXAxis += (BarWidth) + (BarWidthWhitespace); //prepare for adding the next bar in the chart :)
            }
        }