Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4259764
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:49:44+00:00 2026-05-21T05:49:44+00:00

So I’ve made this range bar chart with the MS Chart Control. I have

  • 0

So I’ve made this range bar chart with the MS Chart Control. I have two questions:

  1. How can I implement an event handler for when the user double clicks a series? I can’t see one anywhere.
  2. For some reason the scrollbar on my X Axis (which, amusingly, the Chart Control seems to think is the Y Axis…) seems to be partially transparent for some reason…can anyone shed any light as to why that might be?

Here’s my code so far, bastardised from a PDF I found somewhere on the net (yeah, I know, it’s messy, needs tidying up):

    private void PopulateGantt()
    {
        foreach (Job jobThis in lstJobs)
        {
            if ((jobThis.HireFrom != null) && (jobThis.HireTo != null))
            {
                string xlabel = string.Empty;
                double xordinal = 0;
                double yplot1 = 0;
                double yplot2 = 0;
                yplot1 = (double)((DateTime)jobThis.HireFrom).ToOADate();
                yplot2 = (double)((DateTime)jobThis.HireTo).ToOADate()+1;
                // Use a different series for each datapoint
                Series seriesInstance = new Series();
                // For Gantt charts, we want a RangeBar graph type
                seriesInstance.ChartType = SeriesChartType.RangeBar;
                // Have a start and end date so plotting 2 points on the y-axis
                seriesInstance.YValuesPerPoint = 2;
                // We want to draw datapoint side by side (night is day?)
                seriesInstance.CustomProperties = "DrawSideBySide=false";
                // Add the datapoint to the series, specifying tooltiptext, colorand label

                xordinal = lstJobs.IndexOf(jobThis); //(double)itemIndex;
                seriesInstance.Points.AddXY(xordinal, yplot1, yplot2);

                //seriesInstance.Points[0].Color = resourceColor;
                seriesInstance.Points[0].AxisLabel = xlabel;
                seriesInstance.Label = jobThis.Number + jobThis.Type + " - " + jobThis.ClientCompanyName;
                seriesInstance.Points[0].ToolTip = jobThis.Number + jobThis.Type +
                                "\r\n\r\n" + jobThis.ClientCompanyName +
                                "\r\n\r\n" + jobThis.BriefDescription;

                seriesList.Add(seriesInstance);
            }
            chtHC.Series.Clear();
            foreach (Series plotSeries in seriesList)
            {
                chtHC.Series.Add(plotSeries);
            }
            // Force x-axis to show each task or resource
            chtHC.ChartAreas[0].AxisX.Interval = 1;
            // Set y-axis to show each day of the month
            chtHC.ChartAreas[0].AxisY.Interval = 1;
            // Set x-axis to show in reversed order so dates are displayed leftto-right
            //chtHC.ChartAreas[0].AxisY.IsReversed = true;
            //chtHC.ChartAreas[0].AxisX
            // Set other y-axis properties
            chtHC.ChartAreas[0].AxisY.IsStartedFromZero = false;
            chtHC.ChartAreas[0].AxisY.IsMarginVisible = false;
            chtHC.ChartAreas[0].AxisY.IntervalType = DateTimeIntervalType.Days;
            // Set the y-axis labels
            DateTime? datFirst = null;// = new DateTime();
            DateTime? datLast = null; //= new DateTime();
            //datFirst = (DateTime)lstJobs[0].HireFrom;
            foreach (Job jobFirst in lstJobs)
            {
                if (jobFirst.HireFrom != null)
                {
                    if (datFirst == null)
                    {
                        datFirst = (DateTime)jobFirst.HireFrom;
                    }
                    else
                    {
                        if (jobFirst.HireFrom < datFirst)
                        {
                            datFirst = (DateTime)jobFirst.HireFrom;
                        }
                    }
                }

                if (jobFirst.HireTo != null)
                {
                    if (datLast == null)
                    {
                        datLast = (DateTime)jobFirst.HireTo;
                    }
                    else
                    {
                        if (jobFirst.HireTo > datLast)
                        {
                            datLast = (DateTime)jobFirst.HireTo;
                        }
                    }
                }

            }

            if ((datFirst != null))
            {
                //datLast = ((DateTime)datFirst).AddDays(21);
                chtHC.ChartAreas[0].AxisY.Minimum = ((DateTime)datFirst).AddDays(-1).ToOADate();
                chtHC.ChartAreas[0].AxisY.Maximum = ((DateTime)datLast).AddDays(+1).ToOADate();
            }
            chtHC.ChartAreas[0].CursorY.AutoScroll = true;
            chtHC.ChartAreas[0].AxisY.ScaleView.Zoomable = true;
            chtHC.ChartAreas[0].AxisY.ScaleView.SizeType = DateTimeIntervalType.Days;

            //chtHC.ChartAreas[0].AxisY.LabelStyle.Format = "MMM dd ddd";
            //chtHC.ChartAreas[0].AxisY.LabelStyle.Format = "ddd MMM dd";
            chtHC.ChartAreas[0].AxisY.LabelStyle.Format = "ddd dd/MM/yyyy";
            //chtHC.ChartAreas[0].AxisX.// Force redraw of chart

            chtHC.ChartAreas[0].AxisY.ScaleView.Zoom(chtHC.ChartAreas[0].AxisY.Minimum, chtHC.ChartAreas[0].AxisY.Minimum+21);
            chtHC.ChartAreas[0].AxisY.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll;
            chtHC.ChartAreas[0].AxisY.ScaleView.SmallScrollSize = 1;

            chtHC.Update();
        }
    }
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T05:49:45+00:00Added an answer on May 21, 2026 at 5:49 am

    There’s no specific event able to handle datapoint clicks, but you can use MouseClick event plus HitTest method, e.g.:

    void chart1_MouseClick(object sender, MouseEventArgs e)
    {
        var pos = e.Location;
        var results = chart1.HitTest(pos.X, pos.Y,false, ChartElementType.DataPoint);
        foreach (var result in results)
        {
            if (result.ChartElementType == ChartElementType.DataPoint)
            {
                // use result.Series etc...
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.