piechart using devexpress, pass values from variables - c#

I'm using DevExpress for WinForms (the free one) and I'm using a 3D pie chart.
I already have a chart using the Windows version and all I do is pass four variables as the values the chart needs in the series.
Here's the code I use currently.
double[] yValues = { bottom, bmid, tmid, top};
string[] xNames = { "Greater than 200", "Between 200-100", "Between 100-50", "Below 50" };
chart1.Series[0].Points.DataBindXY(xNames, yValues);
Now, I've made a DevExpress chart and tried to use:
Devchart1.series[0].points
but points.databind does not exist.
Does anyone know how I bind the data like I have using WinForms?
UPDATE
Here's some more things I tried (commented out).
double[] yValues = { bottom, bmid, tmid, top};
string[] xNames = { "Greater than 200", "Between 200-100", "Between 100-50", "Below 50" };
chart1.Series[0].Points.DataBindXY(xNames, yValues);
DataTable chartTable = new DataTable("Table1");
// Add two columns to the table.
chartTable.Columns.Add("Names", typeof(string));
chartTable.Columns.Add("Value", typeof(Int32));
chartTable.Rows.Add("Below 50", top);
chartTable.Rows.Add("Between 50-100", tmid);
chartTable.Rows.Add("Between 100-200", bmid);
chartTable.Rows.Add("Greater than 200", top);
Series series1 = new Series("Series1", ViewType.Pie3D);
chartControl2.Series.Add(series1);
series1.DataSource = chartTable;
series1.ArgumentScaleType = ScaleType.Qualitative;
series1.ArgumentDataMember = "names";
series1.ValueScaleType = ScaleType.Numerical;
series1.ValueDataMembers.AddRange(new string[] { "Value" });
//((Pie3DSeriesView)series1.View). = true;
//((pie)chartControl2.Diagram).AxisY.Visible = false;
chartControl2.Legend.Visible = false;
// Dock the chart into its parent and add it to the current form.
chart1.Dock = DockStyle.Fill;
::UPDATE2::
heres what happens with this code with values 101, 22, 20 and 15.

DevExpress Series has DataSource property for binding.
Check this article. Hope it helps
UPDATE:
I use your code and it seems to work fine
DataTable chartTable = new DataTable("Table1");
// Add two columns to the table.
chartTable.Columns.Add("Names", typeof(string));
chartTable.Columns.Add("Value", typeof(Int32));
chartTable.Rows.Add("Below 50", 10);
chartTable.Rows.Add("Between 50-100", 10);
chartTable.Rows.Add("Between 100-200", 10);
chartTable.Rows.Add("Greater than 200", 10);
Series series1 = new Series("Series1", ViewType.Pie3D);
//chartControl1.Series.Clear();
chartControl2.Series.Add(series1);
series1.DataSource = chartTable;
series1.ArgumentScaleType = ScaleType.Qualitative;
series1.ArgumentDataMember = "names";
series1.ValueScaleType = ScaleType.Numerical;
series1.ValueDataMembers.AddRange(new string[] { "Value" });
//((Pie3DSeriesView)series1.View). = true;
//((pie)chartControl2.Diagram).AxisY.Visible = false;
chartControl2.Legend.Visible = false;

Related

It is possible to remove space between series in Bar Chart?

I'm struggling with this problem that I don't know if it is possible to solve.
I want to remove the space from Orange series, which doesn't contain any data in Session 1.
I'm just using a sample code to make a small graphic.
var serie1 = new Series();
serie1.LegendText = "Banana";
serie1.Points.AddXY("Session 1", 15);
serie1.Points.AddXY("Session 2", 30);
var serie2 = new Series();
serie2.LegendText = "Orange";
serie2.Points.AddXY("Session 2", 25);
var serie3 = new Series();
serie3.LegendText = "Apple";
serie3.Points.AddXY("Session 1", 10);
serie3.Points.AddXY("Session 2", 15);
chart1.Series.Add(serie1);
chart1.Series.Add(serie2);
chart1.Series.Add(serie3);
chart1.AlignDataPointsByAxisLabel();

DotNetHighCharts Pie Chart Labels Show Slice

I am using DotNetHighCharts and playing around with the various chart formats. The Pie Chart labels show “Slice” for each slice of the pie. What parameter is used to change this to the actual name of the slice?
I got this figured out. I was using the PlotOptions like this
.SetPlotOptions(new PlotOptions
{
Pie = new PlotOptionsPie
{
DataLabels = new PlotOptionsPieDataLabels
{
Formatter = "function() { return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %'; }"
}
}
})
However, I wasn’t passing in the names of the datapoint. So I created a namesAndVals object array that was passed into the Data element of the .SetSeries method.
object[] names = new object[] { “Val1", “Val2", “Val3", “Val4" };
object[] vals = new object[] { 11, 12, 13, 14 };
object[,] namesAndVals = new object[4,2];
for (int i = 0; i < names.Count(); i++)
{
namesAndVals[i, 0] = names[i];
namesAndVals[i, 1] = vals[i];
}
If there is a better way to create the final array I’m open to suggestions. Eventually, the gals and names will be driven by a database.

MS Chart X Axis label repeated - showing multiple points for a single item [Range Bar]

I have created a RangeBar MS Chart control that binds with a datatable. This datatable is created based on the below list data.
The problem is that x axis is showing multiple points for same item with different range.
List
MS Chart
X axis represents the 1st column of the list and Y axis values are 3rd and 4th columns. "dt" is the datatable name
Code
chChart.Series["Series1"].ChartType = SeriesChartType.RangeBar;
chChart.Series["Series1"].Points.DataBind(dt.DefaultView, "Number", "Start Time,Stop Time","ToolTip=Name,Label=Name");
Tried binding as different series but still not working.
var IETable = (dt as System.ComponentModel.IListSource).GetList();
chChart.DataBindCrossTable(IETable, "Number", "Number", "Start Time,Stop Time","");
foreach (Series sr in chChart.Series)
{
sr.ChartType = SeriesChartType.RangeBar;
sr.YValueType = ChartValueType.Time;
sr.XValueType = ChartValueType.String;
}
Is there a way to group x axis value for same item so that the bars are in same line?
Note - When using custom labels, only one value is shown for each x axis label.
Add 1 Series into the chart. Then for the Series, make sure YValuesPerPoint = 2.
Add new DataPoints so that the XValue represents the line (in the example for line ABC1, XValue = 1 and line ABC2, XValue = 2. For the DataPoint.AxisLabel you can set the label of that axis (in this case 'ABC1' and 'ABC2'). Then for the YValues, you specify values comma separated, for example 1,2 or 7,20.
Example:
chChart.Series["Series1"].Points.Add(new DataPoint() { AxisLabel = "ABC1", XValue = 1, YValues = new double[] { 2,5 } });
chChart.Series["Series1"].Points.Add(new DataPoint() { AxisLabel = "ABC1", XValue = 1, YValues = new double[] { 6,7 } });
chChart.Series["Series1"].Points.Add(new DataPoint() { AxisLabel = "ABC1", XValue = 1, YValues = new double[] { 9,10 } });
chChart.Series["Series1"].Points.Add(new DataPoint() { AxisLabel = "ABC2", XValue = 2, YValues = new double[] { 3,6 } });
chChart.Series["Series1"].Points.Add(new DataPoint() { AxisLabel = "ABC2", XValue = 2, YValues = new double[] { 7,8 } });
So the key is that the XValue must be same (double?) for all the bars on same line.
Manipulating datapoints individually for each series did the trick. Based on the index of the custom label, i modified the Xvalue of the datapoint. "vn" is a string array that has custom label names.
var IETable = (dt as System.ComponentModel.IListSource).GetList();
chChart.DataBindCrossTable(IETable, "Number","","Start Time,StopTime","");
foreach (Series sr in chChart.Series)
{
sr.ChartType = SeriesChartType.RangeBar;
sr.XValueType = ChartValueType.String;
foreach (DataPoint p in sr.Points)
{
int dpIndex=0;
// foreach unique x axis value, increment dpIndex
//ToDoCode
//aligning the datapoint's X axis value in the middle
p.XValue = dpIndex + 0.5;
}
}

multiple series in column chart asp.net 4.0

I am trying to create a StackedColumn chart in my asp.net application. So I have a datatable like this -
DataTable dtTemp = new DataTable();
dtTemp.Columns.Add("Phase", typeof(string));
dtTemp.Columns.Add("Status", typeof(string));
dtTemp.Columns.Add("Count", typeof(int));
dtTemp.Rows.Add("Initiate", "Pending", 10
dtTemp.Rows.Add("Initiate", "OnHold", 20);
dtTemp.Rows.Add("Initiate", "Rejected", 3);
dtTemp.Rows.Add("Initiate", "Cancelled", 5);
dtTemp.Rows.Add("Initiate", "Pending IT", 2);
dtTemp.Rows.Add("Setup", "Setup", 25);
Now I want the chart to display 2 column, first column will show the Initiate phase data with different status data. And 2nd column will show setup phase data. I have tried like this -
foreach (DataRow row in dtTemp.Rows)
{
string seriesName = row["Status"].ToString();
chart_ProjectStatus.Series.Add(seriesName);
chart_ProjectStatus.Series[seriesName].ChartType = SeriesChartType.StackedColumn;
chart_ProjectStatus.Series[seriesName].ChartArea = "ChartArea1";
chart_ProjectStatus.Series[seriesName].CustomProperties = "DrawingStyle=Cylinder, MaxPixelPointWidth=50";
chart_ProjectStatus.Series[seriesName].Points.AddXY(row["Phase"].ToString(), Convert.ToInt32(row["Count"].ToString()));
}
But I am getting only one column -
Please some one help me.
Thanks in advance
Gulrej
<b> Hope this will Help you </b>
DataTable dtTemp = new DataTable();
dtTemp.Columns.Add("Phase", typeof(string));
dtTemp.Columns.Add("Status", typeof(string));
dtTemp.Columns.Add("Count", typeof(int));
dtTemp.Columns.Add("StackGroupName", typeof(string));
dtTemp.Rows.Add("Initiate", "Pending", 10, "Group1");
dtTemp.Rows.Add("Initiate", "OnHold", 20, "Group1");
dtTemp.Rows.Add("Initiate", "Rejected", 3, "Group1");
dtTemp.Rows.Add("Initiate", "Cancelled", 5, "Group1");
dtTemp.Rows.Add("Initiate", "PendingIT", 2, "Group1");
dtTemp.Rows.Add("Setup", "Setup", 25, "Group2");
dtTemp.Rows.Add("Setup", "INSTALLED", 55, "Group2");
dtTemp.AcceptChanges();
Series ss;
for (int i = 0; i < dtTemp.Rows.Count; i++)
{
ss = new Series();
ss.Name = dtTemp.Rows[i][1].ToString();
ss.ChartType = SeriesChartType.StackedColumn;
ss["StackedGroupName"] = dtTemp.Rows[i]["StackGroupName"].ToString();
ss["DrawingStyle"] = "Cylinder";
ss.Points.AddXY(Convert.ToString(dtTemp.Rows[i]["Phase"]), Convert.ToInt32(dtTemp.Rows[i]["Count"]));
ss.IsValueShownAsLabel = true;
ChartSideBySideStacked.Series.Add(ss);
}
ChartArea chartAread = new ChartArea();
chartAread.Area3DStyle.Enable3D = true;
chartAread.Area3DStyle.Rotation = 5;
chartAread.Area3DStyle.Inclination = 10;
chartAread.Area3DStyle.IsRightAngleAxes = false;
ChartSideBySideStacked.ChartAreas.Add(chartAread);
ChartSideBySideStacked.Legends.Add(new Legend("CHartLEgend"));
ChartSideBySideStacked.AlignDataPointsByAxisLabel(); // Chart Object Name : ChartSideBySideStacked
Enable 3D
U must Provide Stacked Group Name for Each Series
Set Rotation Angle
Set Inclination and IsRightAngleAxes
this one is working fine ... please note i am using VS 2010.. Asp.Net

ASP.net c# help with chart control

i have the following dataset
NAME | GP | ORD_GP | EXP | TOTAL GP | TARGET
a 206 48 -239 15 1600
b 0 27 0 27 1520
iv managed to display the TOTAL GP on the chart using the code
Chart1.BackColor = Color.Gray;
Chart1.BackSecondaryColor = Color.WhiteSmoke;
Chart1.BackGradientStyle = GradientStyle.DiagonalRight;
Chart1.BorderlineDashStyle = ChartDashStyle.Solid;
Chart1.BorderlineColor = Color.Gray;
Chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
// format the chart area
Chart1.ChartAreas[0].BackColor = Color.Wheat;
// add and format the title
Chart1.Titles.Add("TOTAL GP Against TARGET ");
Chart1.Titles[0].Font = new Font("Utopia", 16);
Chart1.Series.Add(new Series("TotalGP")
{
ChartType = SeriesChartType.Column,
});
Chart1.Series.Add(new Series("Target")
{
ChartType = SeriesChartType.Column,
});
Chart1.Series[0].ChartType = SeriesChartType.Column;
DataView dataView = new DataView(ds.Tables[0]);
Chart1.Series[0].Points.DataBindXY(dataView, "NAME", dataView, "TOTAL_GP");
please can some one tell me how i can plot the target on the same chart ?
UPDATE
also how do i get the chart to show the values for each column ?
You just need to databind the second column to some source data
Chart1.Series[1].Points.DataBindXY(dataView, "NAME", dataView, "TARGET");
http://code.google.com/intl/tr-TR/apis/chart/

Categories

Resources