C# MS Chart Control - highlight today's date in Gantt Chart - c#

The title of this question says it all.
I've got a gantt chart (RangeBar) made using the MS Chart Control, and at present I have some StripLines to highlight weekends and the start of each month, but I need one to appear on today's date only so the user can see where we are at the mo.
Is this possible with this control, or am I fishing for unicorns?
If it's possible, how?
Cheers

Nevermind, figured it out:
StripLine strpToday = new StripLine();
strpToday.IntervalOffset = DateTime.Today.ToOADate();
strpToday.StripWidth = 1;
strpToday.BackColor = Color.ForestGreen;
chtHC.ChartAreas[0].AxisY.StripLines.Add(strpToday);

Related

Make dates in datetimepicker grey?

Im writing a hotel booking system with VS2012 which uses ms sql and in the booking i have two datetimepicker controls. When i select a date in the first one the date automatically gets transfered to the second datetimepicker. I now want when the user opens up the second datetimepicker not being able to select a date that is before the first date from the first datetimepicker. I dont want to use if method displaying a message i just want the dates to be "greyed" out.
Is that possible and how?
*edit (screenshot of how i would like it to be viewed or similar http://i43.tinypic.com/2zpimvs.jpg )
*edit2: its not the control(dateTimePicker2) it self i want to grey out, its the dates inside it that is smaller then the date selected in dateTimePicker1. The screenshot provided is in the area of what im looking for.
You could try this:
DateTimePicker2.MinValue = Convert.toDateTime(DateTimePicker1.SelectedDate);
EDIT
Standard controls don't support the grey-out of a datetimepicker. If you want to do this, you need to subclass the datetimepicker or look at a premade control like a DateEdit from devexpress (i think they even have free controls).
Change the second datepicker MinDate to first DatePicker selected date .. like below ..
rdpDatePicker2.MinDate = rdpDatePicker1.SelectedDate.Value;

Asp.net chart control IsValueShownAsLabel and label will display values with $ symbol

I have set IsValueShownAsLabel to true in asp.net chart control.
I am trying to show these visible lables as $100.00 instead of showing only numerics like 100.00 or so.
Is there any way as I understand that only numerics can be visible as lables.
chartSeries.LabelFormat = "${0.00}";
solved my problem
Edit:
The most professional way with hints from prthrokz's comment to the question.
chartSeries.LabelFormat = "{0:C}";

ASP:CHART legend check box series control

I have a fully functioning Dynamic chart control( just the regular ASP.net Chart ) It works great but I've run into a problem trying to add check boxes to the legend. I'm trying to add them next to the series names so the user can hide or view the respective series data. The chart is plotting data for roughly 42 employees. So being able to select and hide data is very important. I've been researching this for a few days now and I've found examples for 3rd party chart tools but i need to do this in MSVS 2010 standard charting tool.
This is how I create the Chart.
for (int emp = 1; emp < empRowList.Length; emp++)
{
chartB.Series.Add(empRowList[emp]);
chartB.Series[empRowList[emp]].ChartType = SeriesChartType.Point;
chartB.Series[empRowList[emp]].MarkerSize = 10;
chartB.Series[empRowList[emp]].MarkerStyle = MarkerStyle.Star4;
for (int month = 1; month < 12; month++)
{
chartB.Series[empRowList[emp]].Points.AddXY(mfi.GetMonthName(month), employeeStats[month, emp]);
chartB.Series[empRowList[emp]].Points[chartB.Series[empRowList[emp]].Points.Count - 1].ToolTip = empRowList[emp] + " - " + employeeStats[month, emp];
}
}
Here is how I format the chart
chartB.DataSource = t.Tables["info"];
chartB.DataBind();
chartB.Legends.Add(new Legend("Legend"));
chartB.Legends["Legend"].Alignment = StringAlignment.Center;
chartB.Legends["Legend"].Docking = Docking.Top;
I looked through this post thinking it could be augmented to help but since his series aren't added dynamically i'm not sure if it is the right direction to pursue.
ASP .net 4 Chart Control Legend formatting is not displaying at all
I've also looked in to using custom legends but read that they aren't linked to the data so i thought that might also be that wrong direction.
If anyone could help it would be greatly appreciated i'm kind of at a stand still till I can figure this out.
Thanks in advance
Some code on this would have been wonderful as I was looking to do something similar.
I did however find a post on msdn that states custom legends are not possible.
http://msdn.microsoft.com/en-us/library/bb677428(v=sql.100).aspx
I was able to find a solution similar to what i wanted using the code from the link above but could never quite get the legend to work properly so i scrapped that idea and just dynamically created a check-box bank underneath my chart that hides/shows series. Wasn't too difficult just needed to create a class and deal with the click event verses the redraw of the graph.

How do I remove an Excel Chart Legend Entry with C#?

I want to remove the legend entry for some, but not all, series in my Excel chart. From my experience it seems as if SeriesCollection.Item(index) and LegendEntries.Item(index) are not related. Given a series n how can I remove only the legend for that series?
I'm using Office Interop 2010 with Visual Studio 2010. This is easily accomplished via the GUI by selecting the legend entry, then right clicking and choosing "delete".
To delete a legend entry you have to know the index of the legend you want to delete. Unfortunately, there doesn't seem to be a relationship available through the interop api that exposes the relationship between legend and series. There is one hokey workaround however. To remove a legend for a specific series the approach that worked for me was to remove the legend immediately after adding the series. This is the only time that the legend index is known.
// .
// . code to add series
// .
// remove the legend entry for the newly added series
chart.Legend.LegendEntries(chart.Legend.LegendEntries().Count).Delete();
I know the original question was about Office Interop 2010, but this seems to be a good reference point for dynamically showing and hiding series in a chart too, so I'll add the following top in case it helps others.
If you want to show/hide a series on a chartobject on a worksheet in Office 2013 (in VBA at least; not sure about interop), you can do the following:
Worksheets("MySheetName").ChartObjects("MyChartName").Chart.FullSeriesCollection("MyLedendSeriesName").IsFiltered = false
This hides the series without removing it. Set it to true to show the series again.
I needed to remove the last two legend entries from a chart because they were fake series added to create a cross-hairs effect. One series made the vertical line and the other horizontal. After the legend entry was removed, the series remained on the chart, which is what I wanted. I used the code below:
Microsoft.Office.Interop.Excel.ChartObject chartObj = null;
Microsoft.Office.Interop.Excel.Chart chart = null;
Microsoft.Office.Interop.Excel.Legend legend = null;
Microsoft.Office.Interop.Excel.LegendEntries legendEntries = null;
Microsoft.Office.Interop.Excel.LegendEntry legendItem;
int legendEntryCount = 0;
chartObj = (Microsoft.Office.Interop.Excel.ChartObject) xlws.ChartObjects("Chart 1");
chart = chartObj.Chart;
legend = chart.Legend;
legendEntries = (Microsoft.Office.Interop.Excel.LegendEntries) chart.Legend.LegendEntries();
legendEntryCount = legendEntries.Count;
if (legendEntryCount > 2)
{
legendItem = (Microsoft.Office.Interop.Excel.LegendEntry) legend.LegendEntries(legendEntryCount);
legendItem.Delete();
legendItem = (Microsoft.Office.Interop.Excel.LegendEntry) legend.LegendEntries(legendEntryCount - 1);
legendItem.Delete();
}

Ms-Chart Label Format Question

I created a PieChart with the new Ms Chart Controls. How can I format the Labels (Point Values inside the Pie) like the folllowing: "LabelName AbsoluteValue (Percentage)"? For example: "Usa 856027 (56 %)".
Is this possible with the right format information in LabelFormat alone (How?) or do I have to use a custom label format (How?) ?
Thank you very much!
Rupert Rand
You can include keywords in the Label property, which can either be set in the GUI(through the Series Collection Editor) or in code. I would recommend setting it through the GUI since it would not require a full knowledge of the available keywords. If you instead want to set it in the code, it would look similar to this (assuming I understand what format you are requesting): Chart.Series(0).Label = "#ValX #Val (#ValPercentY{P0})".

Categories

Resources