Hi everybody,
I'm playing around with RadChart and I want to make the chart dynamic.
I use the flowing code:
When I changed one of the RadCombo Boxes, the Title is updated perfectly but I get the,
extra serries in my chart.
View screenshot.
What is it, that I'm douing wrong ?
I'm playing around with RadChart and I want to make the chart dynamic.
I use the flowing code:
private
static
int
[] huidigJaar = {135, 115, 79, 51, 5};
// ToDo: Values uit webService
private
static
int
[] vorigeJaar = {110, 135, 47, 46, 15 };
// ToDo: Values uit webService
protected
override
void
OnLoad(EventArgs e)
{
if
(!Page.IsPostBack)
{
InitRadChart();
SetGraphValues();
}
RadChart1.Skin =
"Pastel"
;
base
.OnLoad(e);
}
private
void
SetGraphValues()
// Vullen van de Bars in de Grafiek
{
ChartSeries aantalSeries = RadChart1.GetSeries(
"Huidig Jaar"
);
if
(aantalSeries !=
null
)
{
if
(aantalSeries.Items.Count > 0)
{
foreach
(ChartSeriesItem seriesItem
in
aantalSeries.Items)
{
seriesItem.YValue = huidigJaar[seriesItem.Index];
}
}
else
{
for
(
int
i = 0; i < 5; i++)
{
aantalSeries.AddItem(huidigJaar[i]);
}
}
}
ChartSeries aantalVorig = RadChart1.GetSeries(
"Vorig Jaar"
);
// Vorige Jaar
if
(aantalVorig !=
null
)
{
if
(aantalVorig.Items.Count > 0)
{
foreach
(ChartSeriesItem seriesItem
in
aantalVorig.Items)
{
seriesItem.YValue = vorigeJaar[seriesItem.Index];
}
}
else
{
for
(
int
i = 0; i < 5; i++)
{
aantalVorig.AddItem(vorigeJaar[i]);
}
}
}
}
private
void
InitRadChart()
//Initalisatie van de Graph.. hier ook bepalen hoeveel bars.
{
// Titel van chart afhankelijk van wat we gaan tekenen.
const
string
TITLETEXT = @
"Aanvragen in {0} over de tijds periode {1}"
;
RadChart1.ChartTitle.TextBlock.Text =
string
.Format(TITLETEXT,
RadComboBox2.SelectedItem.Text,
RadComboBox1.SelectedItem.Text);
RadChart1.PlotArea.XAxis.Appearance.TextAppearance.TextProperties.Font =
new
Font(
"Verdana"
, 10);
RadChart1.PlotArea.XAxis.Appearance.TextAppearance.TextProperties.Color = Color.LightSlateGray;
RadChart1.AutoLayout =
true
;
RadChart1.PlotArea.XAxis.AutoScale =
false
;
// Moet op False anders wordt de label niet getoont.
RadChart1.PlotArea.XAxis.AddItem(
"Aangevraagd"
);
RadChart1.PlotArea.XAxis.AddItem(
"Uitgebracht"
);
RadChart1.PlotArea.XAxis.AddItem(
"Gepasseerd"
);
RadChart1.PlotArea.XAxis.AddItem(
"Vervallen"
);
RadChart1.PlotArea.XAxis.AddItem(
"Pijplijn"
);
RadChart1.PlotArea.YAxis.VisibleValues = ChartAxisVisibleValues.Positive;
RadChart1.Appearance.BarOverlapPercent = 40;
// Huidige bar over de vorrige heen leggen
RadChart1.Series.Clear();
//Bars voor het vorige jaar.. Wordt gevuld bij SetGraphValues
ChartSeries aantallenVorrig =
new
ChartSeries(
"Vorig Jaar"
, ChartSeriesType.Bar);
RadChart1.AddChartSeries(aantallenVorrig);
aantallenVorrig.Appearance.ShowLabels =
false
;
//Bars voor het huidige jaar.. Wordt gevuld bij SetGraphValues
ChartSeries aantallenHuidig =
new
ChartSeries(
"Huidig Jaar"
, ChartSeriesType.Bar);
RadChart1.AddChartSeries(aantallenHuidig);
aantallenHuidig.Appearance.ShowLabels =
true
;
aantallenHuidig.Appearance.TextAppearance.TextProperties.Color = Color.Black;
}
protected
void
RadComboBox_SelectedIndexChanged(
object
sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
if
((RadComboBox1.SelectedItem !=
null
) && (RadComboBox2.SelectedItem !=
null
) )
{
InitRadChart();
SetGraphValues();
}
}
When I changed one of the RadCombo Boxes, the Title is updated perfectly but I get the,
extra serries in my chart.
View screenshot.
What is it, that I'm douing wrong ?