I have a composite line chart with one x axis and up to 8 y axis. All is good. I have written some code to reset the tick intervals as needed and that works. Now I have two problems. I have axis.TimeAxisStyle.TimeAxisStyle = RulerGenre.Continuous. When I zoom and scroll the x axis values change and the chart area does not scroll only the lines and the x axis labels are pushed down underneath my legend. When I set axis.TimeAxisStyle.TimeAxisStyle = RulerGenre.Discrete the zoom/scroll behavior is what I want (the whole area to scroll left and right and keep x axis label static), however, the x axis disregards all the tickmark interval settings now and overlaps the layers if I choose a larger amount of data records to chart, but the labels are now up from underneath the legend.
Attached pic discreet.jpg show the overlapping and ignoring the tickmark settings
Attached pic continuous1.jpg show the chart set on continuous and the labels are good but continuous2.jpg shows what happens when I zoom/scroll.
continuous1
continuous2
Any ideas?
Hi Michael,
This does not appear to be the expected behavior for the chart. I attempted to reproduce the behavior you're showing here, but I wasn't successful. Are you able to share a sample project with us? I can create a private case if necessary.
Once I am able to reproduce the issue, I will write it up in our system for further review.
This code is embedded deep in an enterprise application but I can give you the core of the code. The data source is a simple data table with a date column (x-axis) and a numeric column (y-axis). SwapRowsAndColumns is set to false and ChartType is Composite.
My chart area is define in this method:
private ChartArea GetChartArea() { var area = new ChartArea(); area.Bounds = new Rectangle(0, 0, 100, 94); area.BoundsMeasureType = MeasureType.Percentage; return area; }
Here is the code that build the x-axis:
private AxisItem DefineXAxisItems(ChartArea area) { var axis = new AxisItem(); axis.ScrollScale.Visible = true; axis.ScrollScale.Scale = 1; axis.ScrollScale.Scroll = 0; axis.ScrollScale.Height = 16; axis.ScrollScale.Width = ultraChart.Width; axis.MajorGridLines.Color = Color.LightSlateGray; //axis.MinorGridLines.Visible = true; //axis.MinorGridLines.Color = Color.LightSlateGray; axis.Key = "Date"; axis.DataType = AxisDataType.Time; axis.Labels.ItemFormat = AxisItemLabelFormat.Custom; axis.Labels.ItemFormatString = "<ITEM_LABEL:MM/dd/yy HH:mm:ss>"; axis.Labels.Orientation = TextOrientation.Custom; axis.Labels.OrientationAngle = -30; axis.TickmarkIntervalType = AxisIntervalType.Hours; axis.TickmarkStyle = AxisTickStyle.Smart; axis.TimeAxisStyle.TimeAxisStyle = RulerGenre.Continuous; // RulerGenre.Discrete; axis.OrientationType = AxisNumber.X_Axis; axis.SetLabelAxisType = SetLabelAxisType.ContinuousData; area.Axes.Add(axis); return axis; }
Create enough data points to have more than 30 points (100 is a pretty good number) along your x-axis. The settings above will create the x-axis with the axis labels spaced apart. When you zoom the axis and then scroll from left to right the date labels will change as the y-axis line scrolls but not the x-axis gridlines.
Now change the axis.TimeAxisStyle.TimeAxisStyle to be RulerGenre.Discrete. Now watch all your x-axis labels be crammed together and overlapping. However, the zooming and scrolling now behaves as desired by having the x-axis major grid lines under the y-axis scroll with the y-axis and the date labels stay static. Even if I set TickmarkStyle to AxisTickStyle.DataInterval and set my TickmarkInterval to a number large enough to try and force the gridlines to spread out the chart ignores the setting and overlaps the x-axis labels.
I hope this helps.
Sorry, the first column in the data source is type DateTime not just date.
Thank you. I will work with the code you provided and attempt to build a reproduction sample.
I am currently working to reproduce this. However, I am seeing very different behavior than what you describe. I have attached the sample that I built based on the code you sent and the description you provided. Please see whether you are able to reproduce the behavior with this sample.
Let's ignore the label overlap for now. Leave TickmarkStyle = Smart. Start the app, zoom the chart and then scroll. Why does the gridlines stay in place while the y-axis line scroll? Watch the date labels change their value as you scroll. What can I do to get the x-axis labels to scroll with the y axis points so the numeric values stayed lined up with their index point on the x axis? Basically anchor the y-axis values to their tickmark on the x-axis. I do not want my x-axis labels to change values as I scroll, I want the whole chart area to scroll.
In the sample that I built, the gridlines seem to behave correctly. I believe that the cause of the gridlines staying in place in your application is not found in the code that you provided. Is there any more grid code in your app? If so, please provide it here.
If you are able to provide your full application, please let me know. I am willing to take a look through the full application to see whether I am able to pin down the cause.
When I run the sample project you sent me the gridlines behave in the manner I am describing. The gridlines do not move.
Here is the whole project that runs the chart. ChartngHost.cs is the form that run s the chart and has all the code in it. The only issue here will be in the Initialize() with passing in your datasets. Just change it to use only the one set called dataSource (that is the chart data). The dataTable named uomData is used to build some tags in the legend. The string dataInterval is just a tag like "HOURLY" or "MINUTE". The meat of the process to build the axes is in 3 methods DefineYAxisItems, DefineXAxisItems, and BuildSeries. All other methods are event handlers and helper methods.
The ChartSelector.cs and the ScaleSelector.cs are forms that assist a node tree view in setting certain attributes at run time and can be removed/ignored as well to prevent issues since you are just passing in a static datasource and running a simple chart. ChartTrending can also be ignored.