This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi Jason, I can't figure out how to achieve a specific graph result, and I'm hoping you can give some advice. The attached graph (Graph1.jpg) is close to what I want to achieve. It shows a time series of monthly returns for an investment as a bar series (the returns are fictitious, though the name is real), and the resulting cumulative growth from 100% as a line series on the right axis. Note that the line series has one additional point representing the initial value (100). Logically the line series values represent values between the bars, not in the middle of the bars as shown. I was thinking maybe I could get what I need by using a value converter on the XBinding for the line series to provide a right-shift of half a month for the line-series x-values. Unfortunately, this gave the result shown in Graph2.jpg, which I won't describe since a picture is worth 1000 words here for sure. Can you recommend a way to get the result I am looking for. Thanks Peter |
|
|
Hi Peter, By default, the axis will use provided objects (including DateTime) and place them along the axis in a first-come-first-served manner to create a category mapping. Try setting the ValueConverter property of the XAxis to be a DateTimeAxisValueConverter which will map each DateTime along a time scale as appropriate. Let me know if that is not going to work for you. -Jason Fauchelle |
|
|
Hi Jason, Thanks for the quick response. Your suggestion works perfectly. I'm glad I asked before I spent a lot of time trying to figure this out myself, because I'm not sure I could have found it. Peter |
|
|
Hi Jason, I guess I hadn't tested the solution you suggested adequately, because I now find that it creates another problem. For these time-series charts we need to control the major ticks so that they always delineate calendar quarters (Jan-Mar, Apr-Jun, etc), calendar half-years (Jan-Jun, Jul-Dec), or calendar years depending on the number of months on the x-axis. We also always want to label the first month of each quarter, half-year, or year. We have been successfully doing this using the MajorTickSpacing, TickMarkOffset, and LabelOffset properties of the axis. However, I now find that when I use the DateTimeAxisValueConverter as you suggested we can no longer control the major ticks with the MajorTickSpacing and TickMarkOffset properties. I gathered from looking at your source code that using DateTimeAxisValueConverter essentially converts the x-axis logical units to ticks, so I have tried specifying my desired MajorTickSpacing and TickMarkOffset in ticks as well, which still doesn't work. Tracing through the ChartAxis.RenderTickMarks code I think I see that in many of the branches that execute when DateTimeAxisValueConverter is used simply ignore the "logicalOffset" variable (which contains the MajorTickSpacing I have specified). Is there a fix for this? Thanks Peter |
|
|
Hi Peter, Try have a go at populating the DateTimeIntervalDefinitions collection of the DateTimeAxisValueConverter. The MinimumTimeSpan and MaximumTimeSpan let you create time-span ranges of when each interval definition should take affect. The IntervalUnit property let you set the date-time units such as Month. The IntervalMagnitude property specifies the number of those units between major tick marks. The IntervalFormat lets you specify how the label at each major tick mark should be displayed. This should allow you to define logic such as if the axis is displaying between 6 and 18 months, then display 3 Months between major tick marks. I hope that helps. -Jason Fauchelle |
|
|
Hi Jason, Thanks for the super-quick response. With the tip about DateTimeAxisValueConverter.DateTimeIntervalDefinitions I seem to have got it working. I find that when using the DateTimeAxisValueConverter the IntervalMagnitude property essentially replaces the ChartAxis.MajorTickSpacing property, and the ChartAxis.TickMarkOffset still needs to be converted to ticks to work properly. I want to mention that I have found it quite tricky to set the ChartAxis.TickMarkOffset to get what I need, because in order to know what offset to use I need to know where the first major tick would be placed with no offset, and the behavior of the chart here is a bit strange and depends on whether or not DateTimeAxisValueConverter is being used. In the case where DateTimeAxisValueConverter is used here is the code to figure the offset that seems to work: double offset = - (tickSpacing + 1) / 2.0; xAxis.TickMarkOffset = offset * ticksMultiplier; And when DateTimeAxisValueConverter is not used here is the code that seems to work: double offset = (tickSpacing - 1) / 2.0 - (dateRange.BegDate.Month - 1) % tickSpacing; xAxis.TickMarkOffset = offset; My point is that while I have it working, getting this to work was inordinately difficult and I worry that this code could easily break in the future because it is based on observed behavior of the chart control, rather than any documented behavior. It seems to me it would be better if the offset was from the start of the my data series, rather that some difficult-to-predict value determined internally by the chart control. Sorry for the complaint--overall I like your chart control a lot. Thanks Peter |
|
|
Hi Peter, Great to hear you got it working. Thanks for your feedback, I also think that configuring the axis could be made easier. -Jason Fauchelle |
|