ASP.NET chart DataBindCrossTable with horizontal bars - c#

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;
}

Related

Align multiple charts

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.

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 ReportViewer Line Chart background

I pass a dataset to my report, which renders a line chart showing a sprint burn down chart. One of the fiends in the dataset is 'PeriodType', which can be either 'Planning, 'Burning' or 'Retrospective'.
The chart shows dates along x axis, and the y axis holds hours.
What I would like to do, is grey the background, where the x axis has a value that is not a 'Burning' period. So the object that is used to create the chart, as mentioned, has a type field I can use.
Is there a way to change the background colour of the x 'columns' based on the flag? Some sort of conditional background colouring? I have searched, but can't seem to find such a handy thing.
Yes, that is possible.
Open the Properties pane, in the BackgroundColor or Color (whichever is relevant) property of the chart, enter an IFF statement like:
=IIF(Str(Fields!PeriodType.Value) <> "Burning", "Gray", "SomeOtherColor")
Hope that helps

How to calculate the column/bar segments width in WPF programatically?

I have googled many times with different keywords, but could not find an e-book for drawing different charts.
Ok my problem is I am drawing a column chart, I want the column chart to calculate the segment width based on the number of segments it has. Does anyone know how I could do this?
Thanks and Regards,
Mawy
Try to use the WPF toolkit, reference System.Windows.Controls.DataVisualization.Toolkit.dll . You can find some samples here, it should be pretty simple, create your collection of KeyValuePair containing your data and then bind to the Key and the Value properties. More about the column charts here. If you use this you won't need extra work for the width or height of the columns.

How do I add a legend to an ASP.NET 3.5 chart control?

Is there a way to add a legend to the chart it creates? I have created a line chart and by default it has created different colors for the different y - axis data. I would like a legend on the side the displays what data goes with which line color.
Thank You.
Your chart control can create a legend using the data series names simply by adding the following line:
chart.Legends.Add(new Legend("Default") { Docking = Docking.Right});

Categories

Resources