Align multiple charts - c#

I have seen this answer, but what happens if you have three charts? And in general, have n charts stacked one ontop of each other and you want the chart bodies (areas) to align with each other?
I would be satisfied to see a result for three charts, but a function that takes a list of charts and aligns them is the most useful.
Also, does this answer presume the charts already have all data in them? What if the data is added at runtime dynamically and you need to keep the charts aligned? The problem is the y-axis labels may change in size as new data appears ( a negative sign appears, or more decimal places, more digits, etc), pushing the chart body to the right, and therefore misligning them with other chart areas stacked above/below it.
Being able to assign a stable Y-axis label extent no matter how big the label gets goes along way to solving some of these problems. How is this done?

This should work, assuming charts is an array of all the charts -
var referenceR = charts
.OrderBy(c => c.ChartAreas[0].InnerPlotPosition.ToRectangleF().Width)
.FirstOrDefault();
foreach(var chart in charts)
{
chart.Left = referenceR.Left;
chart.Size = referenceR.Size;
var r = chart.ChartAreas[0].InnerPlotPosition.ToRectangleF();
chart.ChartAreas[0].InnerPlotPosition = new ElementPosition(referenceR.Left, r.Top, referenceR.Width, r.Height);
}

This solution worked. I realize it is not what I asked, but for now this seems to be the internal design of the chart control "promoted" for solving this sort of problem.
Instead of having three charts, I have one chart with three areas. Then solving the alignment issue is trivial:
chart1.ChartAreas["ChartArea2"].AlignWithChartArea = "ChartArea1";
chart1.ChartAreas["ChartArea3"].AlignWithChartArea = "ChartArea1";
And everything stays aligned beautifully as data is inserted in realtime.

Related

How can I manipulate Winforms chart

I have a problem fitting my chart:
How can I adjust or manipulate the y-axis numbers to start from where I want it?
Secondly, is there a way (properties) which may help me display this graph friendly? As we can see all x-axis name aren't displayed and maybe a space b/w grey and blue bars?
Any help to how to display charts friendly is welcome
You can set the Interval of each Axis:
yourChart.ChartAreas[0].AxisY.Interval = 17;
And you can make it start at any Offset:
yourChart.ChartAreas[0].AxisY.IntervalOffset = 11;
As for the X-Axis Labels it is hard to tell without knowing your code..
..but basically the same options apply here too:
yourChart.ChartAreas[0].AxisX.Interval = 1;
To control the widths of the columns you set their custom property PixelPointWidth but adding a gap is not possible.
All solutions I found are hacks and the best one is to add a dummy Series between the real data series:
chart1.Series[0]["PixelPointWidth"] = "33";
chart1.Series["gap"]["PixelPointWidth"] = "33";
chart1.Series[2]["PixelPointWidth"] = "33";
Fill it with the same number of DataPoints with an X-Value of 0!

ReportViewer RDLC Chart Gap

I've got two chart types sharing one chart area. One of the charts is a smooth area chart (three of this type are generated but only one is shown in the designer), the other is a column chart.
The purpose of the column chart is to indicate where some limits are located on the smooth area chart. The charts are created well except that the smooth area chart has gaps where the limit lines show up.
How do I get rid of the gaps that are occurring? The following images are print screens of my issue.
Thanks
Turns out that the column chart data is included in the C# list that I'm using as a data source for these charts. So, when making the smooth area graphs it is using those red lines values as a data point, causing a gap because they're y value is set to 0. There is no gap, just a 0 value.
The column chart y values are actually a different parameter with a random name but using the same dataset, since the smooth area chart doesn't have that value set, they are effectively 0, so you don't see them show up as columns.
The real problem is that I basically need to show data conditionally, or get two datasets in one chart.

ASP.NET Chart Manipulation with c#

To explain my question I drew an image, here it is:
So I have a Chart that has a bar graph and a line chart, 2 in 1. I am trying to displaly it in asp.net just the way i drew it on here. This means the A box on the image has a set of values which reflect the line graph, and C box on the image has a set of values that define the bar graph values.
What I want to ask is how do I set two different sets of values on a single chart. I know I can use series to draw multiple graphs and by having series defined as different types I can change if its a bar graph or a ilne chart, however I don't know how to add 2 range of values on the side.
As for the the box B, what I wish to ask is how do I set these values so that they are showing different dates, I was able to do it using a line of code shown bellow, however that line of code sets every value to same, and I need them to reflect different values such as range of dates in this example on the image.
Code that I tried is: Chart1.Series["Series1"].AxisLabel = "Test";
Help is most appreciated!
Cheers!
Ok so i'm going to leave this question up for those that come into similar problem.
This is how you set column A and column c
Chart1.Series[0].YAxisType = AxisType.Primary;
Chart1.Series[1].YAxisType = AxisType.Secondary;
Chart1.ChartAreas[0].AxisY.Maximum = 500;
Chart1.ChartAreas[0].AxisY2.Maximum = 7000;
Your grid lines might get messed up so if you want to disable them use
Chart1.ChartAreas[0].AxisY2.MajorGrid.Enabled = false;
And just as a bonus if you want to set intervals on each Y axis you can do that with
Chart1.ChartAreas[0].AxisY.Interval = 50;
I still haven't figured out how to do part B that I mentioned, so if you know the answer then please share.
Cheers!

ASP.NET chart DataBindCrossTable with horizontal bars

I'm using .net 4 charting, and I need to plot a chart that must have several columns grouped together. The solution is to use the DataBindCrossTable function, which perfectly suits my needs; however, the chart needs to be drawed as lines instead of columns. The DataBindCrossTable doesn't seem to work with bar charts, only columns.
Is there a way to rotate the columns horizontally or any other solution ?
Thank you
In the code behind file, change the Series.ChartType value to StackedBar for each series.
C#:
foreach (Series data in chtChartControl.Series)
{
data.ChartType = SeriesChartType.StackedBar;
}

Display unsorted data in SL3 line chart

I'm having trouble with my Silverlight Chart. My model is unsorted, that is, the sorting is done on the server side. It needs to support year transitions, but as you can see from the screenshot the charting control automatically sorts the model and fills in the gaps. The line sort be ever increasing and not taking a dip on new year.
How can I make the chart display the data in the order specified in the grid control to the left?
Btw, using SL3
alt text http://img705.imageshack.us/img705/7602/unsortedsilverlightchar.png
The line chart is not designed to do the task you seem to be asking. After all the purpose of a line chart is to help the user trace a trend or even visually interpolate an interim value. However if the interval between horizontal points is not linear and always traveling in the same direction such lines meaningless.
I would therefore suggest that the Line chart is not appropriate or that you have some other hidden data which should be used for the Y-axis which would make the lines meaningful.
Alternatives might be to use a Scatter graph or a Column series where the y-axis value has been converted to a string and thus cause the series to use a Category based axis instead of range based one.

Categories

Resources