Hi All
I am a relative newbie to charting and Visual Studio and I am
struggling with a problem which is very quickly driving me around the
twist so I Wonder if anyone can help.
I am Using Visual Studio (c#) to create a web application (.net 3.5)
with the Microsoft Chart and I am creating a StackedColumn chart. I
have a chart with 2 series. All is fine apart from 1 problem with data
correctly displayed.
I retrieve fields TheCount, TheYear, TheWeek from a database table for
each series (one is failed tests, the other passed tests). Each
dataset will usually consist of 5 records for the last 5 weeks.
What I want to achieve is to have the individual major X-Axis tickmark
labels to be the 'TheWeek' column values retrieved from each database
record.
Example, What I have at the moment is (See code below) for weeks 22,
23, 24, 25 is
500 x
400 x x
300 x x x
200 x x x
100 x x x x
1 2 3 4 <-- These labels are the problem
whereas what I need is
500 x
400 x x
300 x x x
200 x x x
100 x x x x
22 23 24 25 <- They should be the week numbers retrieved
from the database
Can anyone tell me how to change this text dynamically as it is
driving me nuts.
Many thanks in advance for any assistance offered.
Iain
con.Open();
cmdAll.Connection = con;
cmdAll.CommandType = CommandType.Text;
cmdAll.CommandText = SelectionStringPass;
OleDbDataReader dsMetersAll = cmdAll.ExecuteReader();
Chart1.Series["Series1"].IsValueShownAsLabel = true;
Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = false;
Chart1.Series["Series1"].ChartType =
SeriesChartType.StackedColumn;
Chart1.Series["Series1"]["DrawingStyle"] = "Emboss";
Chart1.Series["Series1"].IsValueShownAsLabel = true;
Chart1.Series["Series2"].ChartType =
SeriesChartType.StackedColumn;
Chart1.Series["Series2"]["DrawingStyle"] = "Emboss";
Chart1.Series["Series2"].IsValueShownAsLabel = true;
// Read the dataset
xPoint = 1;
// I read through the dataset becasue I will manipulate the
data for other uses
while (dsMetersAll.Read())
{
string tempString = dsMetersAll["TheCount"].ToString();
countAll = int.Parse(tempString);
Chart1.Series["Series1"].Points.AddXY(xPoint, countAll);
Chart1.Series["Series1"].XValueMember =
dsMetersAll["TheWeek"].ToString();
// I have tried this but it does not work
// Chart1.Series["Series1"].XValueMember =
dsMetersAll["TheWeek"].ToString();
xPoint = xPoint + 1;
}
}
else
{
lblInfoLabel.Text = "No Data Availble To Display";
}
// Now get the fails
int countFails = 0;
cmdFail.Connection = con;
cmdFail.CommandType = CommandType.Text;
cmdFail.CommandText = SelectionStringFail;
OleDbDataReader dsMeterFails = cmdFail.ExecuteReader();
xPoint = 1;
while (dsMeterFails.Read())
{
string tempString = dsMeterFails["TheCount"].ToString();
countFails = int.Parse(tempString);
Chart1.Series["Series2"].Points.AddXY(xPoint, countFails);
xPoint = xPoint + 1;
}
con.Close();