I am trying to plot a composite chart with two Y axis (numeric values) and X axis = datetime. The values are appearing on both Y axis but I dont see the line charts or anything on X axis , basically the body of the chart is blank...
I cant figure out where I am making a mistake...
ds.Tables[0] has three columns X datetime , Y numeric , Y2 numeric...
UltraChart composite1 = new UltraChart(); //composite1.ChartType = Infragistics.UltraChart.Shared.Styles.ChartType.Composite; composite1.ChartType = ChartType.Composite; composite1.DataSource = ds.Tables[0]; ChartArea area = new ChartArea(); composite1.CompositeChart.ChartAreas.Add(area); //AxisItem x = new AxisItem( composite1, AxisNumber.X_Axis); AxisItem x = new AxisItem(); x.OrientationType = AxisNumber.X_Axis; x.DataType = AxisDataType.Time ; x.SetLabelAxisType = SetLabelAxisType.ContinuousData; x.Labels.ItemFormat = AxisItemLabelFormat.ItemLabel; area.Axes.Add(x); //AxisItem y = new AxisItem(composite1, AxisNumber.Y_Axis); AxisItem y = new AxisItem(); y.OrientationType = AxisNumber.Y_Axis; y.DataType = AxisDataType.Numeric; y.Labels.ItemFormat = AxisItemLabelFormat.DataValue; area.Axes.Add(y); //AxisItem y2 = new AxisItem(composite1, AxisNumber.Y2_Axis); AxisItem y2 = new AxisItem(); y2.OrientationType = AxisNumber.Y2_Axis; y2.DataType = AxisDataType.Numeric; y2.Labels.ItemFormat = AxisItemLabelFormat.DataValue; area.Axes.Add(y2); NumericSeries s1 = new NumericSeries(); s1.Data.DataSource = ds.Tables[0]; s1.Data.ValueColumn = "Y"; s1.Data.LabelColumn = "X"; s1.DataBind(); composite1.CompositeChart.Series.Add(s1); NumericSeries s2 = new NumericSeries(); s2.Data.DataSource = ds.Tables[0]; s2.Data.ValueColumn = "Y2"; s2.Data.LabelColumn = "X"; s2.DataBind(); composite1.CompositeChart.Series.Add(s2); ChartLayerAppearance layer1 = new ChartLayerAppearance(); layer1.AxisX = x; layer1.AxisY = y; layer1.ChartArea = area; layer1.ChartType = ChartType.LineChart; layer1.Series.Add(s1); composite1.CompositeChart.ChartLayers.Add(layer1); ChartLayerAppearance layer2 = new ChartLayerAppearance(); layer2.AxisX = x; layer2.AxisY = y2; layer2.ChartArea = area; layer2.ChartType = ChartType.LineChart; layer2.Series.Add(s2); // layer2.SwapRowsAndColumns = true; composite1.CompositeChart.ChartLayers.Add(layer2); composite1.Height = 600; composite1.Width = 1300; this.WebPanel1.Controls.Add(composite1);
I modified the code in the past few days and have reached a point where I am able to plot the charts. I have a problem and it could be becoz I am probably unaware of what to use for my specific purpose. I have a dataset X = datetime , Y = numeric , Y2 = numeric. Fill in any values you want its just that Y is always positive and Y2 is always negative with a few 0 values. My problem is even though I get both lines and both the Y axis have the ranges I set, the Y2 line doesnt originate from Y2 axis, it still belongs to Y axis. So for the longest time I couldnt se the y2 line and then I changed the Y axis range to from e.g. 0 to 20 to -20 to 20. Following is the code
{
// Add the chart area.
chart.CompositeChart.ChartAreas.Add(myChartArea);
xAxis.OrientationType = AxisNumber.X_Axis;
xAxis.Labels.OrientationAngle = -26;
xAxis.DataType = AxisDataType.Time;
xAxis.Labels.Visible = true;
xAxis.TickmarkStyle = AxisTickStyle.Smart;
chart.CompositeChart.ChartAreas[0].Axes.Add(xAxis);
y2Axis.OrientationType = AxisNumber.Y2_Axis;
y2Axis.TickmarkStyle = AxisTickStyle.Smart;
y2Axis.Labels.VerticalAlign = System.Drawing.StringAlignment.Near;
y2Axis.Labels.Visible = true;
y2Axis.MajorGridLines.Visible = true;
y2Axis.RangeMin = -15;
y2Axis.RangeMax = 0;
chart.CompositeChart.ChartAreas[0].Axes.Add(y2Axis);
yAxis.OrientationType = AxisNumber.Y_Axis;
yAxis.TickmarkStyle = AxisTickStyle.Smart;
yAxis.Labels.VerticalAlign = System.Drawing.StringAlignment.Near;
yAxis.Labels.Visible = true;
yAxis.MajorGridLines.Visible = true;
yAxis.RangeMin = -20;
yAxis.RangeMax = 20;
myChartArea.Axes.Add(yAxis);
// Create a data series.
series.Key = "Value";
series.Data.DataSource = getData();
chart.CompositeChart.Series.Add(series);
//NumericSeries series2 = new NumericSeries();
series2.Key = "Value2";
series2.Data.DataSource = getData();
chart.CompositeChart.Series.Add(series2);
// Create a ChartLayerAppearance for the series.
seriesLayer.ChartArea = chart.CompositeChart.ChartAreas[0];
seriesLayer.AxisX = xAxis;
seriesLayer.AxisY = yAxis;
//seriesLayer.AxisY2 = y2Axis;
chart.CompositeChart.ChartLayers.Add(seriesLayer);
seriesLayer.Series.Add(series);
seriesLayer.Series.Add(series2);
ChartLayerAppearance y2layer = new ChartLayerAppearance();
y2layer.ChartType = ChartType.LineChart;
y2layer.ChartArea = chart.CompositeChart.ChartAreas[0];
y2layer.AxisX = xAxis;
y2layer.AxisY2 = y2Axis;
chart.CompositeChart.ChartLayers.Add(y2layer);
y2layer.Series.Add(series2);
y2layer.Visible = true;
*/
}
table.Columns.Add("Date", typeof(DateTime));
table.Columns.Add("Value2", typeof(double));
table.Rows.Add(new object[ { "11/05/2007", 8 , 0});
table.Rows.Add(new object[ { "11/21/2007", 10 ,-5});
table.Rows.Add(new object[ { "11/23/2007", 13,-6});
return table;
Since you are using a time axis, you need a series that supports time values. NumericSeries can only have one numeric value and one string value. If you use a NumericTimeSeries instead, you can specify a time value for each point of your line chart.