Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
465
Composite Chart with multiple series
posted

Excuse this post if the questions has already been covered.  I am trying to create a composite chart showing actual and plan numbers by day, as columns on a chart.  The chart also has a line showing a weighted average value.  Data comes from a SQL stored procedure.  The resulting chart looks like this:

 

This is not exactly the result that I want.  I am trying to get the columns for each day to be next to each other.  For example, the columns for Saturday would be side-by-side, not in two separate sets of columns.  It should look something like this:

 

 Below is the code that I am using.  Thanks in advance for your assistance.

DataTable tbldata = new DataTable();

 

 

string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["MCISSQLConnection"].ConnectionString;
SqlConnection sTransConn = new SqlConnection(strConn);
SqlCommand sTransCmd = new SqlCommand();
sTransCmd.Connection = sTransConn;
sTransConn.Open();
sTransCmd.CommandText = "MCIS_PortalPart_KPI_Graph '" + "Stanislaus" + "', " + "5";
SqlDataReader objTransReader = sTransCmd.ExecuteReader();
// Add the fields to the data table to populate.
tbldata.Columns.Add("day", typeof(string));
tbldata.Columns.Add("Actual", typeof(int));
tbldata.Columns.Add("Plan", typeof(int));
tbldata.Columns.Add("Moving Average", typeof(int));
// Add the rows.
while (objTransReader.Read())
{
    tbldata.Rows.Add(new object[] { objTransReader["NameShort"].ToString(), objTransReader["Transports_System"], objTransReader["Transports_System_Plan"], objTransReader["Transports_System_MovAvg"] });
 }
 sTransConn.Close();
sTransConn.Dispose();
sTransCmd.Dispose();
objTransReader.Close();
objTransReader.Dispose();
this.ultraChart1.ChartType = ChartType.Composite;
this.ultraChart1.Data.SwapRowsAndColumns = true;
ChartArea area = new ChartArea();
this.ultraChart1.CompositeChart.ChartAreas.Add(area);
AxisItem xAxisColumn = new AxisItem(this.ultraChart1, AxisNumber.X_Axis);
 
AxisItem xAxisLine = new AxisItem(this.ultraChart1, AxisNumber.X_Axis);
AxisItem yAxis = new AxisItem(this.ultraChart1, AxisNumber.Y_Axis);
xAxisColumn.DataType = AxisDataType.String;
xAxisColumn.SetLabelAxisType = SetLabelAxisType.GroupBySeries;
xAxisColumn.Labels.ItemFormat = AxisItemLabelFormat.ItemLabel;
 
xAxisLine.DataType = AxisDataType.String;
xAxisLine.SetLabelAxisType = SetLabelAxisType.ContinuousData;
yAxis.DataType = AxisDataType.Numeric;
yAxis.Labels.ItemFormat = AxisItemLabelFormat.DataValue;
yAxis.RangeType = AxisRangeType.Custom;
yAxis.RangeMin = 0;
yAxis.RangeMax = 100;
 
area.Axes.Add(xAxisColumn);
area.Axes.Add(xAxisLine);
area.Axes.Add(yAxis);
 
NumericSeries seriesColumn = new NumericSeries();
seriesColumn.Data.DataSource = tbldata;
seriesColumn.Data.LabelColumn = "day";
seriesColumn.Data.ValueColumn = "Actual";
 
NumericSeries seriesColumn2 = new NumericSeries();
seriesColumn2.Data.DataSource = tbldata;
seriesColumn2.Data.LabelColumn = "day";
seriesColumn2.Data.ValueColumn = "Plan";
 
NumericSeries seriesLine = new NumericSeries();
seriesLine.Data.DataSource = tbldata;
seriesLine.Data.LabelColumn = "day";
seriesLine.Data.ValueColumn = "Moving Average";
 
this.ultraChart1.Series.AddRange(new Infragistics.UltraChart.Data.Series.ISeries[] { seriesLine, seriesColumn, seriesColumn2 });
 
ChartLayerAppearance columnLayer = new ChartLayerAppearance();
columnLayer.AxisX = xAxisColumn;
columnLayer.AxisY = yAxis;
columnLayer.ChartArea = area;
columnLayer.ChartType = ChartType.ColumnChart;
columnLayer.Series.Add(seriesColumn);
columnLayer.Series.Add(seriesColumn2);
//columnLayer.Series.AddRange(new Infragistics.UltraChart.Data.Series.ISeries[] {seriesColumn, seriesColumn2 });
ChartLayerAppearance lineLayer = new ChartLayerAppearance();
lineLayer.AxisX = xAxisLine;
lineLayer.AxisY = yAxis;
lineLayer.ChartArea = area;
lineLayer.ChartType = ChartType.LineChart;
lineLayer.Series.Add(seriesLine); 
 
this.ultraChart1.CompositeChart.ChartLayers.Add(columnLayer); 
this.ultraChart1.CompositeChart.ChartLayers.Add(lineLayer); 
this.ultraChart1.ColumnChart.SeriesSpacing = 0;
 
Parents
  • 26458
    Offline posted

    Try adding this to the column layer:
    columnLayer.SwapRowsAndColumns = true;

    This should give you 5 groups of 2 columns instead of 2 groups of 5.

Reply Children
No Data