Fair warning : I am a novice when it comes to charting.
I am using the following data table below in a line chart currently with the exception of "Metric 4" and it works just great. What I need to do now is include "Metric 4" as a column chart behind the current line chart.
I have messed around with this data table in a ColumnLineChart (which appears to be what I need to use) but I can't get it to work. Basically I need row 4 of the DataTable to be used as the datasource of the column chart. Do I need to just make a separate data table both the column and the line chart?
-----------------------------
DataTable dt = new DataTable();
var columnDateString = new DataColumn("DateValue", typeof(string)); dt.Columns.Add(columnDateString);
dt.Columns.Add("11/1", typeof(int)); dt.Columns.Add("11/8", typeof(int)); dt.Columns.Add("11/15", typeof(int)); dt.Columns.Add("11/22", typeof(int)); dt.Columns.Add("11/29", typeof(int));
dt.Rows.Add(new object[] { "% Metric 1", 0, 10 ,25,50, 80}); dt.Rows.Add(new object[] { "% Metric 2", 0, 8, 20, 45, 70 }); dt.Rows.Add(new object[] { "% Metric 3", 0, 2, 5, 8 , 8 }); dt.Rows.Add(new object[] { "Metric 4", 0, 20, 25, 25, 25 });
Never mind, I figured it out.
Argh..actually only partially
Using the data below gets me the look I want but I have 3 questions
1) How can I use the line data as the legend?
2) I need the scale and the range of the column chart data to be based on dtColChart data, right now it is stuck at 100 even though one of the data points in there is 255.
3) How can I adjust the thickness of the column data plots?
--
dt.Columns.Add("11/1", typeof(double)); dt.Columns.Add("11/8", typeof(double)); dt.Columns.Add("11/15", typeof(double)); dt.Columns.Add("11/22", typeof(double)); dt.Columns.Add("11/29", typeof(double));
dt.Rows.Add(new object[] { "% Coverage", 0, 10 ,25,50, 80}); dt.Rows.Add(new object[] { "% Pass To Plan", 0, 8, 20, 45, 70 }); dt.Rows.Add(new object[] { "% Gated", 0, 2, 5, 8 , 8 });
DataTable dtColChart = new DataTable(); var colDate = new DataColumn("DateValue", typeof(string)); dtColChart.Columns.Add(colDate);
dtColChart.Columns.Add("11/1", typeof(double)); dtColChart.Columns.Add("11/8", typeof(double)); dtColChart.Columns.Add("11/15", typeof(double)); dtColChart.Columns.Add("11/22", typeof(double)); dtColChart.Columns.Add("11/29", typeof(double));
dtColChart.Rows.Add(new object[] { "Metric 4", 0, 20, 56, 95, 255 });
this.ultraChart1.ColumnLineChart.ColumnData.DataSource = dtColChart; this.ultraChart1.ColumnLineChart.ColumnData.DataBind(); this.ultraChart1.ColumnLineChart.LineData.DataSource = dt; this.ultraChart1.ColumnLineChart.LineData.DataBind();
Since the ColorModel will use the same color for columns and some lines, I recommend this approach... handle the ChartDrawItem event:
void UltraChart1_ChartDrawItem(object sender, ChartDrawItemEventArgs e)
{
Box b = e.Primitive as Box;
if (b != null && b.Layer is ColumnLayer)
b.PE = new PaintElement(Color.Yellow);
}
David,
Thanks for the help that was exactly what I needed. It is all so easy once you know how :) One last question. I am using these 3 colors for the line portion of the chart (see below), how can i have the column chart use a 4th color? Currently when it binds the column chart data it uses Color.SteelBlue for the color as expected but how can I change that to something else?
Color[] chartColors = new Color[] { Color.SteelBlue, Color.LimeGreen, Color.Red };ultraChart1.ColorModel.ModelStyle = ColorModels.CustomLinear;ultraChart1.ColorModel.CustomPalette = chartColors;
DmgInc said: 1) How can I use the line data as the legend?
this.ultraChart1.Legend.Visible = true; this.ultraChart1.Legend.DataAssociation = ChartTypeData.LineData;
DmgInc said: 2) I need the scale and the range of the column chart data to be based on dtColChart data, right now it is stuck at 100 even though one of the data points in there is 255.
i didn't experience that when i ran this code. the y-axis goes up to 255. please make sure Axis.Y.RangeType is set to Auto.
DmgInc said: 3) How can I adjust the thickness of the column data plots?
this.ultraChart1.ColumnLineChart.Column.ColumnSpacing = 1;
either that, or set some margins on the x-axis using the properties under Axis.X.Margins.
i am attaching a picture of what i see when i add a new chart to a form, set the ChartType to ColumnLineChart, and paste your code into Form1_Load, along with my changes suggested above.