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

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();

Related

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

zedgraph text values at xaxis, and show Integers at y axis

First thing is... The y axis show values with a comma as default. I want them to show integers instead. How do I do this?
As you can see on the x axis, the months are all messed up according to the graph. The graph that you see should start at Jun, so, the months before that should not appear. I cannot erase the months before June, because there are cases where they are needed shown. How can I go about with this?
Besides showing the month, I also want to show the year. So fx. the year of the month Jun was 98. So It should show Jun-98, and Nov-99
Thanks in advance.
Here is some of my code:
string[] months = {"Jan, Feb, Mar, April, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec"};
int[] monthCount = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
pane.XAxis.Type = AxisType.Text;
pane.X2Axis.IsVisible = true;
pane.X2Axis.Title.Text = "Totally " + totaRegistering + " registrations in the entire period";
pane.YAxis.Scale.IsReverse = false;
pane.X2Axis.Type = AxisType.Text;
pane.XAxis.Scale.Min = minXValueToScale;
pane.XAxis.Scale.Max = maxXValueToScale;
pane.YAxis.Scale.Min = minYValToScale;
pane.YAxis.Scale.Max = maxYValToScale;
double[] xVal = new double[tableCount], yVal = new double[tableCount];
for (int i = 0; i < dataSet.Tables[objectName].Rows.Count; i++ )
{
xVal[i] = Convert.ToInt32(dataSet.Tables[objectName].Rows[i][resForXAxis]);
yVal[i] = Convert.ToInt32(dataSet.Tables[objectName].Rows[i][resForYAxis]);
}
list1 = new PointPairList(xVal, yVal);
curve1 = pane.AddCurve("Male and Female", list1, Color.Green, SymbolType.Circle);
pane.XAxis.Scale.TextLabels = months;
curve1.Line.Width = 2.0F;
pane.GetImage().Save(outputDest, ImageFormat.Png);
I know this question is no longer relevant for someome who asked it, but may be it will be useful for some other people.
pane.YAxis.Scale.MinorStep = 1;
pane.YAxis.Scale.MinorStepAuto = false;
pane.YAxis.Scale.MajorStep = 1;
pane.YAxis.Scale.MajorStepAuto = false;
pane.YAxis.Scale.Format = "0";
pane.XAxis.Scale.Format = "0";
These settings will make only integers to be shown.

Creating an object array of two value arrays dynamically – application: highcharts dotnet

I'm hoping to get a quick solution to this.
Here is a snippet of the code that works when creating a series:
Series SeriesABC2 = new Series
{
Name = '#' + HakuAlueet[1],
Data = new Data(
new object[]{
new[] { 300, 440 },
new[] { 400, 540 }
}),
PlotOptionsArearange = new PlotOptionsArearange { Visible = true, LineWidth = 0, FillOpacity = 0.3 },
Type = ChartTypes.Arearange
};
Now the plan is to make this dynamic creating the values in the object "new[] { 300, 440 }, new[] { 400, 540 }" inside .net C#. I'm quite new to C# so I'm not quite sure of the naming convention, but I seem to need to make an array object of an two value arrays. How would I go about this?
I've tried countless ways of managing this but just haven't found a solution that would be acceptable to dotnet.Highcharts. Thanks!
string[] books= source.Select(a => a.bookName).ToArray();
object[] visits = source.Select(a => (object)a.Visits).ToArray();
DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts("chart")
.InitChart(new Chart { DefaultSeriesType = ChartTypes.Bar,
Width = 900
}).SetPlotOptions(new PlotOptions {
Bar = new PlotOptionsBar {
ColorByPoint = true,
DataLabels = new PlotOptionsBarDataLabels {
Enabled = true }
}
}).SetXAxis(new XAxis { Categories = books,
}).SetSeries(new Series
{
Data = new Data(visits),
Name = "User Book Visits"
});
lb_chart.Text = chart.ToHtmlString();
Here source contain data where I am querying some dynamic content. This is working and hope this will also help you.

Sorting IEnumerable in LINQ [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Sorting an IEnumerable in LINQ
Is it possible to sort this one by not using .ToList()?
Please see codes below.
The code below will result to this output.
{ id = 1, name = "sample 1", list = {'a','f','d'}},
{ id = 5, name = "sample 1", list = {'a','f','c'}},
{ id = 2, name = "sample 1", list = {'g','b'}},
{ id = 4, name = "sample 1", list = {'i','e','h'}},
{ id = 6, name = "sample 1", list = {'d','b','c'}},
{ id = 3, name = "sample 1", list = {'h','i','c'}},
Thanks
RJ
IEnumerable<extra> eList = new List<extra>()
{
new extra{ id = 1, text = "a"},
new extra{ id = 2, text = "g"},
new extra{ id = 3, text = "i"},
new extra{ id = 4, text = "e"},
new extra{ id = 5, text = "f"},
new extra{ id = 6, text = "d"},
new extra{ id = 7, text = "c"},
new extra{ id = 8, text = "h"},
new extra{ id = 9, text = "b"}
};
IEnumerable<sample> sam = new List<sample>()
{
new sample{ id = 1, name = "sample 1", list = new List<int>{1,5,6}},
new sample{ id = 2, name = "sample 2", list = new List<int>{2,9}},
new sample{ id = 3, name = "sample 3", list = new List<int>{8,3,7}},
new sample{ id = 4, name = "sample 4", list = new List<int>{3,4,8}},
new sample{ id = 5, name = "sample 5", list = new List<int>{1,5,7}},
new sample{ id = 6, name = "sample 6", list = new List<int>{6,9,7}}
};
var sorted = (from d1 in sam
select new
{
name = d1.name,
id = d1.id,
list =
(
from d2 in d1.list
join e in eList on d2 equals e.id
select e.text
).OrderBy(item => item).ToList()
}).OrderBy(item => item.list.FirstOrDefault());
Maybe ThenBy will do it?
var sorted = (from d1 in sam
select new
{
name = d1.name,
id = d1.id,
list =
(
from d2 in d1.list
join e in eList on d2 equals e.id
select e.text
).OrderBy(item => item
}).ThenBy(item => item.list.FirstOrDefault());
I misunderstood the question. Why not just remove the ToList? You probably want to have .ToList() though to prevent sorting each time you access the collection.
I've just tested your original code without 'ToList' and it sorts the items AND the 'extras' just fine.. Could you elaborate what exactly you want to achieve? Proof:
result of your original code with ToList:
1 "sample 1" a d f
5 "sample 5" a c f
2 "sample 2" b g
6 "sample 6" b c d
3 "sample 3" c h i
4 "sample 4" e h i
result of your code without ToList:
1 "sample 1" a d f <-- adf is sorted
5 "sample 5" a c f <-- also sorted
2 "sample 2" b g <-- and here too
6 "sample 6" b c d <-- yep
3 "sample 3" c h i <-- it is!
4 "sample 4" e h i <-- ...
^
|
\ aabbce is sorted, too
looks identical to me :)
As for the general idea, the small problem the same written in LINQ syntax without that "ToList" is that JOIN would be executed lazily, once per item, and each time it would build the mapping/join from scratch, while it is perfectly cacheable and reusable. Below, in expanded syntax, I explicitly pre-create the mapping only once, then all the other lazy queries without any materializations use share the same mapping. This way it may be several times faster and use less memory:
var mapping = eList.ToDictionary(x => x.id, x=>x.text);
var temps = sam.Select(s =>
new {
id = s.id,
name = s.name,
stringlist = s.list.Select(id => mapping[id]).OrderBy(str => str)
});
var result = temps.OrderBy(t => t.stringlist.FirstOrDefault());
Try this:
var sorted = (from d1 in sam
select new
{
name = d1.name,
id = d1.id,
list =
(
from d2 in d1.list
join e in eList on d2 equals e.id
select e.text
)
}).OrderBy(item => item.list.OrderBy(i => i).FirstOrDefault());

piechart using devexpress, pass values from variables

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;

Categories

Resources