Hi,
The graph i have developed just has numbers from 1 onwars in the x-axis. I want to have strings added to x-axis label. I am generating the chart dynamically.
My COde is like this. I want to have the date in the IDictionary displayed as string in the x-axis.
protected void Page_Load(object sender, EventArgs e)
{
IDictionary<DateTime, int> cmcValues = new Dictionary<DateTime, int>();
cmcValues.Add(DateTime.Today.Date, 115);
cmcValues.Add(DateTime.Today.AddDays(1).Date, 123);
cmcValues.Add(DateTime.Today.AddDays(5).Date, 136);
cmcValues.Add(DateTime.Today.AddDays(23).Date, 143);
cmcValues.Add(DateTime.Today.AddDays(41).Date, 134);
BuildChart(cmcValues, "Diabetes", "Bar");
}
private void BuildChart(IDictionary<DateTime, int> CareMeasureValues, string chartName, string chartType)
{
RadChart rChart = new RadChart();
double stepDate = CareMeasureValues.ElementAt(1).Key.ToOADate();
rChart.ChartTitle.TextBlock.Text = "";
ChartSeries cSeries = new ChartSeries();
cSeries.Name = chartName;
ChartSeriesType csType = new ChartSeriesType();
foreach (string item in Enum.GetNames(csType.GetType()))
{
if (item == chartType)
{
cSeries.Type = (ChartSeriesType) Enum.Parse(csType.GetType(), chartType);
break;
}
}
ChartSeriesItem csItem;
ChartAxisItem cAxisItem;
rChart.PlotArea.XAxis.Clear();
foreach (KeyValuePair<DateTime, int> kvp in CareMeasureValues)
{
csItem = new ChartSeriesItem();
csItem.YValue = kvp.Value;
cAxisItem = new ChartAxisItem();
cAxisItem.TextBlock.Text = kvp.Key.ToShortDateString();
cAxisItem.Value = kvp.Value;
rChart.PlotArea.XAxis.Items.Add(cAxisItem);
cSeries.AddItem(csItem);
}
double firstDate = CareMeasureValues.First().Key.AddDays(-1).ToOADate();
double lastDate = CareMeasureValues.Last().Key.AddDays(1).ToOADate();
rChart.PlotArea.XAxis.AddRange(CareMeasureValues.Count - (CareMeasureValues.Count - 1), CareMeasureValues.Count, 1);
rChart.PlotArea.XAxis.Appearance.MajorGridLines.Visible = false;
rChart.PlotArea.Appearance.Dimensions.Margins = "18%, 24%, 22%, 10%";
rChart.PlotArea.XAxis.AutoScale = false;
rChart.PlotArea.XAxis.Appearance.LabelAppearance.RotationAngle = 45;
rChart.PlotArea.XAxis.Appearance.LabelAppearance.Position.AlignedPosition = Telerik.Charting.Styles.AlignedPositions.Top;
rChart.PlotArea.XAxis.LayoutMode = Telerik.Charting.Styles.ChartAxisLayoutMode.Inside;
rChart.PlotArea.Appearance.Corners.BottomLeft = Telerik.Charting.Styles.CornerType.Round;
rChart.PlotArea.Appearance.Corners.BottomRight = Telerik.Charting.Styles.CornerType.Round;
rChart.PlotArea.Appearance.Corners.TopLeft = Telerik.Charting.Styles.CornerType.Round;
rChart.PlotArea.Appearance.Corners.TopRight = Telerik.Charting.Styles.CornerType.Round;
rChart.AddChartSeries(cSeries);
//HtmlTable table = new HtmlTable();
//HtmlTableRow tRow = new HtmlTableRow();
//HtmlTableCell tCell = new HtmlTableCell();
//tCell.Controls.Add(rChart);
//tRow.Cells.Add(tCell);
//table.Rows.Add(tRow);
placeholder1.Controls.Add(rChart);
}
The graph i have developed just has numbers from 1 onwars in the x-axis. I want to have strings added to x-axis label. I am generating the chart dynamically.
My COde is like this. I want to have the date in the IDictionary displayed as string in the x-axis.
protected void Page_Load(object sender, EventArgs e)
{
IDictionary<DateTime, int> cmcValues = new Dictionary<DateTime, int>();
cmcValues.Add(DateTime.Today.Date, 115);
cmcValues.Add(DateTime.Today.AddDays(1).Date, 123);
cmcValues.Add(DateTime.Today.AddDays(5).Date, 136);
cmcValues.Add(DateTime.Today.AddDays(23).Date, 143);
cmcValues.Add(DateTime.Today.AddDays(41).Date, 134);
BuildChart(cmcValues, "Diabetes", "Bar");
}
private void BuildChart(IDictionary<DateTime, int> CareMeasureValues, string chartName, string chartType)
{
RadChart rChart = new RadChart();
double stepDate = CareMeasureValues.ElementAt(1).Key.ToOADate();
rChart.ChartTitle.TextBlock.Text = "";
ChartSeries cSeries = new ChartSeries();
cSeries.Name = chartName;
ChartSeriesType csType = new ChartSeriesType();
foreach (string item in Enum.GetNames(csType.GetType()))
{
if (item == chartType)
{
cSeries.Type = (ChartSeriesType) Enum.Parse(csType.GetType(), chartType);
break;
}
}
ChartSeriesItem csItem;
ChartAxisItem cAxisItem;
rChart.PlotArea.XAxis.Clear();
foreach (KeyValuePair<DateTime, int> kvp in CareMeasureValues)
{
csItem = new ChartSeriesItem();
csItem.YValue = kvp.Value;
cAxisItem = new ChartAxisItem();
cAxisItem.TextBlock.Text = kvp.Key.ToShortDateString();
cAxisItem.Value = kvp.Value;
rChart.PlotArea.XAxis.Items.Add(cAxisItem);
cSeries.AddItem(csItem);
}
double firstDate = CareMeasureValues.First().Key.AddDays(-1).ToOADate();
double lastDate = CareMeasureValues.Last().Key.AddDays(1).ToOADate();
rChart.PlotArea.XAxis.AddRange(CareMeasureValues.Count - (CareMeasureValues.Count - 1), CareMeasureValues.Count, 1);
rChart.PlotArea.XAxis.Appearance.MajorGridLines.Visible = false;
rChart.PlotArea.Appearance.Dimensions.Margins = "18%, 24%, 22%, 10%";
rChart.PlotArea.XAxis.AutoScale = false;
rChart.PlotArea.XAxis.Appearance.LabelAppearance.RotationAngle = 45;
rChart.PlotArea.XAxis.Appearance.LabelAppearance.Position.AlignedPosition = Telerik.Charting.Styles.AlignedPositions.Top;
rChart.PlotArea.XAxis.LayoutMode = Telerik.Charting.Styles.ChartAxisLayoutMode.Inside;
rChart.PlotArea.Appearance.Corners.BottomLeft = Telerik.Charting.Styles.CornerType.Round;
rChart.PlotArea.Appearance.Corners.BottomRight = Telerik.Charting.Styles.CornerType.Round;
rChart.PlotArea.Appearance.Corners.TopLeft = Telerik.Charting.Styles.CornerType.Round;
rChart.PlotArea.Appearance.Corners.TopRight = Telerik.Charting.Styles.CornerType.Round;
rChart.AddChartSeries(cSeries);
//HtmlTable table = new HtmlTable();
//HtmlTableRow tRow = new HtmlTableRow();
//HtmlTableCell tCell = new HtmlTableCell();
//tCell.Controls.Add(rChart);
//tRow.Cells.Add(tCell);
//table.Rows.Add(tRow);
placeholder1.Controls.Add(rChart);
}