Microsoft Silverlight charting odd interval -
in simple microsoft chart control in silverlight have days of 1 month dates on x axis , double values on y axis. display every second day on x axis days should odd days.
if set intervaltype="days" , interval="2" numbering starts day 2. if put dummy date in front or in end or both.
instead of: __ 02 __ 04 __ 06 __ 08 __ 10 ...
i need: 01 __ 03 __ 05 __ 07 ...
how can achieve in simplest way?
example set 31.01 -> 1.02 -> 3.02
instead of 31.01 -> 2.02
. in case 1 way write custom axis
similar datetimeaxis
.
at first copy project following files:
- c:\program files\microsoft sdks\silverlight\v4.0\toolkit\apr10\source\source code.zip\controls.datavisualization.toolkit\enumerablefunctions.cs
- c:\program files\microsoft sdks\silverlight\v4.0\toolkit\apr10\source\source code.zip\controls.datavisualization.toolkit\valuehelper.cs
copy these files same namespace, internal there not name conflict. next, add extended class datetimeintervaltype
:
namespace system.windows.controls.datavisualization.charting { /// <summary> /// date time interval. /// </summary> public enum extendeddatetimeintervaltype { /// <summary> /// automatically determine interval. /// </summary> auto = 0, /// <summary> /// interval type milliseconds. /// </summary> milliseconds = 1, /// <summary> /// interval type seconds. /// </summary> seconds = 2, /// <summary> /// interval type minutes. /// </summary> minutes = 3, /// <summary> /// interval type hours. /// </summary> hours = 4, /// <summary> /// interval type days. /// </summary> days = 5, /// <summary> /// interval type weeks. /// </summary> weeks = 6, /// <summary> /// interval type months. /// </summary> months = 7, /// <summary> /// interval type years. /// </summary> years = 8, /// <summary> /// interval type odd days /// </summary> odddays = 9 } }
to make new member odddays
work, i've changed class datatimerangeaxis
. here link on pastebin, because programmers of don't pay attention such trifle answers long explanation.
change namespace silverlightapplication3
whatever want (except system.windows.controls.datavisualization.charting
).
also i've commented code @ last function, because contains many dependencies , didn't want copy files application. axis works fine without code, function isn't used @ all.
the important part of class in function incrementdatetime
:
//the interval type forced user, not actual interval type if (this.intervaltype == extendeddatetimeintervaltype.odddays) { datetime newdate; if(span != timespan.zero) //automatically created interval newdate = date.add(span); else newdate = date.adddays(interval); //else use interval set user //find nearest odd day while (newdate.day % 2 != 1) newdate = newdate.adddays(1); //update span span = newdate - date; }
xaml so:
<charting:chart.axes> <local:datetimeaxis intervaltype="odddays" orientation="x" interval="1"/> </charting:chart.axes>
you can set interval="2"
instead of 1, skip day in set 31.01-1.02-3.02
, better use value 1.
Comments
Post a Comment