Click here to Skip to main content
14,932,270 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to fill the colors to charts based on times, Here I may confusing to do this task. For this I tried below code.

Example: Assume have the below (Class) start and end time and shift start and end time:

In the chart there are <a href="https://ibb.co/f0RvyL5">3 Series</a>.

Work Time needs to fill with Green Color
Over time needs to fill Blue Color
Break time needs to fill with Red color.
The Validations are below.


if(AST < SST)

"Break Time".

else if(AET > SET)

"Over Time".

else
"Work Time".


Sample Chart Link

Above conditions are not working for me.

Can you please help on this?

Thank you.

What I have tried:

ASP.NET
<dx:WebChartControl ID="WebChartControl1" runat="server"
            ToolTipEnabled="False"
            RenderFormat="Svg"
            Height="500px" Width="900px">
            <Legend Name="Default Legend"></Legend>
            <SeriesSerializable>
            </SeriesSerializable>
            <SeriesTemplate ArgumentScaleType="Qualitative" ValueScaleType="DateTime">
                <ViewSerializable>
                    <cc1:OverlappedGanttSeriesView>
                        <FillStyle FillMode="Gradient">
                            <OptionsSerializable>
                                <cc1:RectangleGradientFillOptions Color2="YellowGreen"
                                    GradientMode="BottomToTop" />
                            </OptionsSerializable>
                        </FillStyle>
                    </cc1:OverlappedGanttSeriesView>
                </ViewSerializable>
            </SeriesTemplate>
        </dx:WebChartControl>


C#
 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Session["dummyCl"] = null;
            GetTempWMCenterClasses();
            BindCharts();
        }
    }

public class tempWMCenterClass
{
    public string No { get; set; }
    public string StartTime { get; set; }
    public string EndTime { get; set; }

}

 TimeSpan tempShiftStartTime;
    TimeSpan tempShiftEndTime;
    TimeSpan tempActualStartTime;
    TimeSpan tempActualEndTime;

    DateTime tempDtShiftStartTime;
    DateTime tempDtShiftEndTime;
    DateTime tempDtActualStartTime;
    DateTime tempDtActualEndTime;

List<tempWMCenterClass> objTemp = new List<tempWMCenterClass>();

    private List<tempWMCenterClass> GetTempWMCenterClasses()
    {
        if (Session["dummyCl"] == null)
        {
            objTemp.Add(new tempWMCenterClass { No = "DrillPress", StartTime = "10:00:00 AM", EndTime = "1:00:00 PM" });
            objTemp.Add(new tempWMCenterClass { No = "DrillPress", StartTime = "2:00:00 PM", EndTime = "4:00:00 PM" });
            objTemp.Add(new tempWMCenterClass { No = "DrillPress", StartTime = "5:00:00 PM", EndTime = "7:00:00 PM" });

            objTemp.Add(new tempWMCenterClass { No = "PUMA", StartTime = "6:00:00 AM", EndTime = "11:02:00 AM" });
            objTemp.Add(new tempWMCenterClass { No = "PUMA", StartTime = "2:00:00 PM", EndTime = "4:00:00 PM" });
            objTemp.Add(new tempWMCenterClass { No = "PUMA", StartTime = "5:00:00 PM", EndTime = "7:00:00 PM" });
            Session["dummyCl"] = objTemp;
        }
        else
            objTemp = (List<tempWMCenterClass>)Session["dummyCl"];
        return objTemp;
    } 

 private void BindCharts()
    {
        if (Session["dummyCl"] != null)
            objTemp = (List<tempWMCenterClass>)Session["dummyCl"];


  WebChartControl1.Series.Add(new Series("Order Status Time", ViewType.Gantt));
        WebChartControl1.Series[0].ValueScaleType = ScaleType.DateTime;
        WebChartControl1.Series[0].ArgumentScaleType = ScaleType.Qualitative;

        WebChartControl1.Series.Add(new Series("Order Status Time Empty", ViewType.Gantt));
        WebChartControl1.Series[1].ValueScaleType = ScaleType.DateTime;
        WebChartControl1.Series[1].ArgumentScaleType = ScaleType.Qualitative;

        WebChartControl1.Series.Add(new Series("Order Status Time Over", ViewType.Gantt));
        WebChartControl1.Series[2].ValueScaleType = ScaleType.DateTime;
        WebChartControl1.Series[2].ArgumentScaleType = ScaleType.Qualitative;


 int tempIndex = 0;
        int lastIndex = 0;

        var objDistrict = objTemp.Select(n => n.No).Distinct().ToList();

        for (int i = 0; i < objDistrict.Count(); i++)
        {

            if (string.IsNullOrEmpty(objDistrict[i]))
                return;

            DateTime.TryParse("7:00:00 AM", out tempDtShiftStartTime);
            DateTime.TryParse("4:00:00 PM", out tempDtShiftEndTime);

            tempShiftStartTime = tempDtShiftStartTime.TimeOfDay;
            tempShiftEndTime = tempDtShiftEndTime.TimeOfDay;

            for (int j = 0; j < objTemp.Count(); j++)
            {
                if (objDistrict[i] == objTemp[j].No)
                {

                    DateTime.TryParse(objTemp[j].StartTime, out tempDtActualStartTime);
                    DateTime.TryParse(objTemp[j].EndTime, out tempDtActualEndTime);

                    tempActualStartTime = tempDtActualStartTime.TimeOfDay;
                    tempActualEndTime = tempDtActualEndTime.TimeOfDay;

                    if (tempIndex == 0)
                    {
                        if (tempActualStartTime > tempShiftStartTime)
                            WebChartControl1.Series[1].Points.Add(new SeriesPoint(objDistrict[i], new DateTime[] { tempDtShiftStartTime, tempDtActualStartTime }));
                        else
                           WebChartControl1.Series[0].Points.Add(new SeriesPoint(objDistrict[i], new DateTime[] { tempDtActualStartTime, tempDtActualEndTime }));
                    }
                    else if (lastIndex == j)
                    {
                        if (tempActualEndTime > tempShiftEndTime)
                           WebChartControl1.Series[2].Points.Add(new SeriesPoint(objDistrict[i], new DateTime[] { tempDtShiftEndTime, tempDtActualEndTime }));
                        else
                           WebChartControl1.Series[0].Points.Add(new SeriesPoint(objDistrict[i], new DateTime[] { tempDtActualStartTime, tempDtActualEndTime }));
                    }
                    else
                    {
WebChartControl1.Series[0].Points.Add(new SeriesPoint(objDistrict[i], new DateTime[] { tempDtActualStartTime, tempDtShiftEndTime }));
                    }
                    lastIndex = objTemp.Count() - 1;
                    tempIndex++;
                }
            }
            tempIndex = 0;
        }
}
Posted
Updated 10-Mar-21 18:37pm
v10
Comments
Richard MacCutchan 10-Mar-21 8:03am
   
What do you mean by "not working"? What are the DateTime values that you are using to do the compare operations?
Bojjaiah 10-Mar-21 8:19am
   
Assume the Shift Time is 7 AM to 4 PM. 1) If the user worked between 7 AM to 4 PM then green 2) If the user taken breaks/stopped work between 7 AM to 4 PM the color is Red 3) If the user worked before or after the shift time the color is green. We need to fill these colors to chart according to list of data.
Richard MacCutchan 10-Mar-21 8:54am
   
You cannot solve programming problems with assumptions. Use your debugger to see exactly what values you are dealing with.
Richard Deeming 10-Mar-21 9:28am
   
Two things to consider:

Users aren't allowed to take a lunch break or go to the toilet? That is probably illegal.

What about overnight shifts?
Bojjaiah 10-Mar-21 9:39am
   
break means, they will start the work/machine center and then stop. Example the order have 5Qty. He may start the work/machine center and finished, So he will stop the work and post the 1Qty. And again this process will continue until complete the 5Qty.
Bojjaiah 10-Mar-21 9:40am
   
Overnight Shifts => We need to fill/show some colors to on this cases.
Bojjaiah 11-Mar-21 0:39am
   
Richard, see updated thread.
BillWoodruff 10-Mar-21 10:40am
   
The incomplete code you show does not provide any information about user data. We can't read your mind.
Bojjaiah 10-Mar-21 10:43am
   
Will get the data from GetTempWMCenterClasses() method.
Bojjaiah 11-Mar-21 0:39am
   
Bill, see updated thread.
Gerry Schmitz 10-Mar-21 13:08pm
   
I don't see any "chart related" code that one could color. A lot of attention here being paid to "fill the colors". Not.
Bojjaiah 10-Mar-21 23:39pm
   
Gerry, Here I am not posted the entire code how the data pulling to chart and showcase the color to chart. my logic will comes in the place of "Work Time", "Over Time" and "Break Time".
Bojjaiah 11-Mar-21 0:39am
   
Gerry, see updated thread.
Gerry Schmitz 11-Mar-21 13:40pm
   
It looks like DeVExpress (Why no tag?)

https://docs.devexpress.com/AspNet/15894/components/chart-control/concepts/creating-charts/2d-chart-types/point-chart

Bojjaiah 11-Mar-21 23:40pm
   
Yes, it's a DevExpress control see the thread I am adding the time to webchartcontrol **WebChartControl1.Series[0].Points.Add();WebChartControl1.Series[1].Points.Add();WebChartControl1.Series[2].Points.Add();**

And also please find the Sample Chart Link in the thread.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900