Jan
100
120
20.00%
Feb
130
-23.08%
Mar
160
70
-56.25%
Apr
200
-50.00%
May
180
140
-22.22%
Jun
170
190
11.76%
I have got the datas Month in the X- axis and Sales1 and Sales2 as the bar columns. I also need to have the growth marked on the graph. The growth values should be marked on the right Y-axis along with the growth points connected in the graph. I am using the following code which gives me a partial result.
Cmd = new SqlCommand (Procedure, Conn);
Reader = Cmd.ExecuteReader();
DT =
new DataTable();
DT.Columns.Add(
"Month", typeof(System.String));
"Sales1", typeof(System.Int32));
"Sales2", typeof(System.Int32));
"Percentage", typeof(System.String));
while(Reader.Read())
{
DT.Rows.Add(
new object[] { Reader.GetSqlValue(0), Reader.GetValue(1), Reader.GetValue(2), Reader.GetSqlValue(3) });
}
Reader.Close();
ultraChart1.Axis.Y.RangeType = Infragistics.UltraChart.Shared.Styles.
AxisRangeType.Custom;
ultraChart1.Axis.Y.RangeMin = 0;
ultraChart1.Axis.Y.RangeMax = 200;
ultraChart1.Axis.Y2.Visible =
true;
ultraChart1.Axis.Y2.LineDrawStyle = Infragistics.UltraChart.Shared.Styles.
LineDrawStyle.Solid;
ultraChart1.Axis.Y2.LineColor =
Color.White;
//ultraChart1.Axis.Y2.RangeType = Infragistics.UltraChart.Shared.Styles.AxisRangeType.Custom;
//ultraChart1.Axis.Y2.RangeMin = -70.00;
//ultraChart1.Axis.Y.RangeMax = 30.00;
//ultraChart1.Axis.Y2.TickmarkInterval = 10;
ultraChart1.DataSource = DT;
ultraChart1.Data.DataBind();
Any suggesstions?
Thanks & Regards
Ferdin
For BarChart, I think the best way to show the data you have, would be to group them on Y axis. Try the following code and see it addresses your scenario.
private void Form1_Load(object sender, EventArgs e) { ultraChart1.ChartType = Infragistics.UltraChart.Shared.Styles.ChartType.BarChart; ultraChart1.DataSource = GetData(); ultraChart1.Data.DataBind();
ultraChart1.Axis.Y.Labels.SeriesLabels.Orientation = Infragistics.UltraChart.Shared.Styles.TextOrientation.Custom; ultraChart1.Axis.Y.Labels.SeriesLabels.OrientationAngle = 45;
ChartTextAppearance growthText = new ChartTextAppearance(); growthText.Column = 0; growthText.Row = -2; growthText.VerticalAlign = StringAlignment.Center; growthText.HorizontalAlign = StringAlignment.Near; growthText.ItemFormatString = "<DATA_VALUE>%"; growthText.Visible = true; growthText.FontColor = Color.Black; ultraChart1.BarChart.ChartText.Add(growthText);
ChartTextAppearance salesText1 = new ChartTextAppearance(); salesText1.Column = 2; salesText1.Row = -2; salesText1.VerticalAlign = StringAlignment.Center; salesText1.HorizontalAlign = StringAlignment.Near; salesText1.ItemFormatString = "<DATA_VALUE>"; salesText1.Visible = true; salesText1.FontColor = Color.White; ultraChart1.BarChart.ChartText.Add(salesText1);
ChartTextAppearance salesText2 = new ChartTextAppearance(); salesText2.Column = 1; salesText2.Row = -2; salesText2.VerticalAlign = StringAlignment.Center; salesText2.HorizontalAlign = StringAlignment.Near; salesText2.ItemFormatString = "<DATA_VALUE>"; salesText2.Visible = true; salesText2.FontColor = Color.White; ultraChart1.BarChart.ChartText.Add(salesText2); }
private DataTable GetData() { DataTable mydata = new DataTable(); mydata.Columns.Add("Series Labels", typeof(string)); mydata.Columns.Add("Growth", typeof(double)); mydata.Columns.Add("Sales2", typeof(int)); mydata.Columns.Add("Sales1", typeof(int)); mydata.Rows.Add(new Object[] { "Jan", 20.00, 120, 100 }); mydata.Rows.Add(new Object[] { "Feb", -23.08, 100, 130 }); mydata.Rows.Add(new Object[] { "Mar", -56.25, 70, 160 }); mydata.Rows.Add(new Object[] { "Apr", -50.00, 100, 200 }); mydata.Rows.Add(new Object[] { "May", -22.22, 140, 180 }); mydata.Rows.Add(new Object[] { "Jun", 11.76, 190, 170 }); return mydata; }
Hi Sam,
Thanks for the reply i am sorry i made a mistake i'm not looking for the bar chart, i am looking for the column chart in which the Sales1, Sales2 of Month should be displayed and the growth of Month should be marked on the same chart as points and the points connected to each other. Is there any way to achieve this?
Thanks in advance
Prabhakaran
I have changed it to a ColumnChart. Is this any close to what you are looking for?
I am looking for like this. Is it possible to achieve this?
Sam,
Thank you for the support which you gave me.
Sam atlast i got the chart as expected using the Composite chart which includes Column Chart as first layer and Scatter Chart as the Second layer.
Once again i thank you for the support.
Thanks
Yes, with a some minor changes it can be renderred as a ColumnChart, here is the code - simply copy and paste, and test it.
private void Form1_Load(object sender, EventArgs e) { //*** Changed to ColumnChart ---------------------- ultraChart1.ChartType = Infragistics.UltraChart.Shared.Styles.ChartType.ColumnChart; ultraChart1.DataSource = GetData(); ultraChart1.Data.DataBind();
ultraChart1.Axis.X.Labels.SeriesLabels.Orientation = Infragistics.UltraChart.Shared.Styles.TextOrientation.Horizontal;
ultraChart1.Legend.Visible = true;
ChartTextAppearance salesText1 = new ChartTextAppearance(); salesText1.Column = 0; salesText1.Row = -2; salesText1.VerticalAlign = StringAlignment.Near; salesText1.HorizontalAlign = StringAlignment.Center; salesText1.ItemFormatString = "<DATA_VALUE>"; salesText1.Visible = true; salesText1.FontColor = Color.Blue; ultraChart1.ColumnChart.ChartText.Add(salesText1);
ChartTextAppearance salesText2 = new ChartTextAppearance(); salesText2.Column = 1; salesText2.Row = -2; salesText2.VerticalAlign = StringAlignment.Near; salesText2.HorizontalAlign = StringAlignment.Center; salesText2.ItemFormatString = "<DATA_VALUE>"; salesText2.Visible = true; salesText2.FontColor = Color.Yellow; ultraChart1.ColumnChart.ChartText.Add(salesText2);
ChartTextAppearance growthText = new ChartTextAppearance(); growthText.Column = 2; growthText.Row = -2; growthText.VerticalAlign = StringAlignment.Near; growthText.HorizontalAlign = StringAlignment.Center; growthText.ItemFormatString = "<DATA_VALUE>%"; growthText.Visible = true; growthText.FontColor = Color.Black; ultraChart1.ColumnChart.ChartText.Add(growthText); }
private DataTable GetData() { DataTable mydata = new DataTable(); mydata.Columns.Add("Series Labels", typeof(string)); mydata.Columns.Add("Sales1", typeof(int)); mydata.Columns.Add("Sales2", typeof(int)); mydata.Columns.Add("Growth", typeof(double)); mydata.Rows.Add(new Object[] { "Jan", 100, 120, 20.00 }); mydata.Rows.Add(new Object[] { "Feb", 130, 100, -23.08 }); mydata.Rows.Add(new Object[] { "Mar", 160, 70, -56.25 }); mydata.Rows.Add(new Object[] { "Apr", 200, 100, -50.00 }); mydata.Rows.Add(new Object[] { "May", 180, 140, -22.22 }); mydata.Rows.Add(new Object[] { "Jun", 170, 190, 11.76 }); return mydata; }