I have problem with this chart of a Chart control in ASP.NET 4.0 programmatically
I can not show the values in the SeriesChartType FastLine.
I have added in the script:
Chart1.Series["Price"].IsValueShownAsLabel = true;
But the values are not shown.
What am I missing?
What's wrong with this code?
Thank you in advance.
My code below.
Chart1.Series.Add("Price");
Chart1.Series["Price"].YValueMembers = "Price";
Chart1.Series["Price"].ChartType = SeriesChartType.FastLine;
Chart1.Series["Price"]["LabelStyle"] = "Center";
Chart1.Series["Price"]["PointWidth"] = "0.85";
Chart1.Series["Price"].IsValueShownAsLabel = true;
Chart1.Series["Price"].Font = new System.Drawing.Font("Verdana", 9, FontStyle.Bold);
Chart1.Series["Price"].LabelForeColor = System.Drawing.Color.FromArgb(0, 0, 128);
Chart1.Series["Price"]["LabelStyle"] = "Top";
Chart1.Series["Price"].Color = System.Drawing.Color.FromArgb(153, 153, 255);
Chart1.Series["Price"]["PixelPointDepth"] = "1.0";
Chart1.Series["Price"]["DrawingStyle"] = "Cylinder";
Chart1.Series["Price"].BorderWidth = 3;
Chart1.Series["Price"].MarkerColor = Color.Red;
Marker and DataPointLabels are not supported for FastLine chart.
According to MSDN:
Some charting features are omitted from the FastLine chart to improve performance.
The features omitted include control of point level visual attributes, markers, data point labels, and shadows.
So if you want to show label/datapoints, use Line chart instead.
Related
I'm creating an Excel file by x++, in Dynamics 365 - D365, I would like to add the background color by X++.
I'm using this code
System.IO.Stream workbookStream = new System.IO.MemoryStream();
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
var package = new OfficeOpenXml.ExcelPackage(memoryStream)
var package = new OfficeOpenXml.ExcelPackage(memoryStream)
var worksheets = package.get_Workbook().get_Worksheets();
var worksheet = worksheets.Add("SHEET");
var cells = worksheet.get_Cells();
var currentRow=1 ;
var cell = cells.get_Item(currentRow,1);
cell.set_Value("__MY__Value");
// NOT Work - compile error
//cell.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color::FromArgb(190, 0, 0));
//cell.Style.Fill.BackgroundColor.Rgb(Winapi::rgb2int(255,255,255));
Both commented lines give a Invalid token '('. compiler error.
How can I use the Background color property about Excel cell, by X++ in right way?
Thanks in advance.
As is often the case when doing .Net Interop from x++, the compiler can be a bit difficult if you mix a chain of properties and method calls. It usually helps to put the last property of the chain into its own variable and then call the method on that variable.
So instead of writing
cell.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color::FromArgb(190, 0, 0));
write this instead:
ExcelColor backgroundColor = cell.Style.Fill.BackgroundColor;
backgroundColor.SetColor(System.Drawing.Color::FromArgb(190, 0, 0));
This will get rid of the Invalid token '('. error.
However, now a runtime exception System.ArgumentException: Can't set color when patterntype is not set. is thrown. This is because OpenOfficeXml expects a fill style along with a background color so that Excel knows how the background color should be applied to the background. See the GettingStartedSample.cs#L57-L64.
I wrote the following code as a runnable class example that produces an Excel file with two values with background colors.
using OfficeOpenXml;
using OfficeOpenXml.Style; // note the additional namespace
class SOCreateExcelWithBackgroundColor
{
public static void main(Args _args)
{
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
using (var package = new ExcelPackage(stream))
{
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add('CellBackground');
// add some values and colors
ExcelRange cell = worksheet.Cells.get_Item('A1');
cell.Value = 'Value1';
ExcelFill fill = cell.Style.Fill;
fill.PatternType = ExcelFillStyle::Solid;
ExcelColor backgroundColor = fill.BackgroundColor;
backgroundColor.SetColor(System.Drawing.Color::FromArgb(0, 87, 183));
cell = worksheet.Cells.get_Item('A2');
cell.Value = 'Value2';
fill = cell.Style.Fill;
fill.PatternType = ExcelFillStyle::Solid;
backgroundColor = fill.BackgroundColor;
backgroundColor.SetColor(255, 255, 215, 0); // note that the first 255 defines the transparency (alpha value) of the color
package.Save();
}
File::SendFileToUser(stream, 'CellBackground.xlsx');
}
}
}
This creates the following Excel:
I have been trying to render a line chart using the basic asp.net Chart class. Whatever I do, it always renders a column chart.
Here is my code where I am binding a datatable to the chart.
var IEtable = (table as System.ComponentModel.IListSource).GetList();
var chart = new Chart(width: 1000, height: 1000)
.AddSeries(chartType: "Line").AddLegend("Key")
.AddTitle("Time Series Metric")
.DataBindCrossTable(IEtable, "Key", "Date", "Value");
Can anyone please help? I am been breaking my head with this thing since more than 12 hours now.
I'm building my charts slightly differently - perhaps because I'm building mine in MVC pages?
Anyway, I'm still using the MS Chart stuff - http://msdn.microsoft.com/en-us/library/ee410579.ASPX
I create my chart:
var chart = new Chart();
chart.Width = 900;
chart.Height = 500;
...lots more options...
then add my series one at a time....
chart.Series.Add(CreateDataSeries(id, "GI Lower", null, null, GetGILowerDataPoints));
chart.Series.Add(CreateDataSeries(id, "GI Upper", null, null, GetGIUpperDataPoints));
where CreateDataSeries sets the chart type like this:
Series seriesDetail = new Series();
seriesDetail.ChartType = SeriesChartType.Spline;
...
return seriesDetail;
Does that help at all?
Im working with MS chart control .net 4.0
CharTemp.Series[seriesName].IsValueShownAsLabel = true;
CharTemp.Series[seriesName].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line;
My chart may show 3-4 series depend on input data so i want to change the Forecolor of point label as the same as serie's line color.
Please tell me if there is a way to do it.
chartSellInArea.Series["AttaintoForecast"].ChartType = SeriesChartType.Line;
chartSellInArea.Series["AttaintoForecast"].Color = Color.Orange;
chartSellInArea.Series["AttaintoForecast"].IsValueShownAsLabel = true;
chartSellInArea.Series["AttaintoForecast"].LabelBackColor = Color.Orange;
I am using Microsoft Visual Studio 2010 XtraReports package 1.0 and MVC DX11.2 Report Controls
I am working on producing various Bar Charts. I need to produce a horizontal bar chart and can see that there is a solution for DevExpress.XtraCharts.v12.1 but it uses XYDiagram.Rotated Property.
(see http://documentation.devexpress.com/#XtraCharts/DevExpressXtraChartsXYDiagram_Rotatedtopic)
This is not available for me in DX11.2
Can anyone suggest how horizontal bar charts be created either using the chart designer or in code?
Many thanks
Jeff
DX 11.2 also have same property. Check the following code snippet of DX 11.2 demos
if (settings.Diagram is XYDiagram) {
((XYDiagram)settings.Diagram).Rotated = options.Rotated;
Axis2D axisY = ((XYDiagram)settings.Diagram).AxisY;
axisY.Interlaced = true;
axisY.Title.Text = "Population, millions";
axisY.Title.Visible = true;
}
else {
XYDiagram3D diagram = (XYDiagram3D)settings.Diagram;
diagram.AxisX.Label.MaxWidth = 60;
diagram.AxisY.Interlaced = true;
diagram.RotationType = RotationType.UseAngles;
diagram.RotationOrder = RotationOrder.XYZ;
diagram.ZoomPercent = 140;
diagram.VerticalScrollPercent = 4;
}
Html.DevExpress().Chart(settings)
.Bind(Model)
.Render();
Check your DevExpress Demos folder for Chart
Demo(C:\Users\Public\Documents\DevExpress 2011.2
Demos\Components\ASP.NET\MVC\CS\MVCDemos\Views\Chart), there you will
get the partial view file name "BarViewsSideBySideStackedPartial"
which help to implement this.
Hope this help.
I'm trying to generate sparklines for a dashboard using the Microsoft chart control on ASP.net. Sparklines generally have no axes or anything other than the data points showing.
I've succesfully turned off most of the lines but I'm stuck with one horizontal and one vertical line I can't figure out how to get rid of. Here's what I see:
Here's what I want:
Here's an excerpt of the code I'm using (minus the actual data):
Chart2.Width = 100;
Chart2.Height = 60;
Chart2.BorderlineWidth = 0;
var name = "Northeast Region";
ChartArea area = new ChartArea(name);
area.AxisX.LabelStyle.Enabled = false;
area.AxisY.LabelStyle.Enabled = false;
area.AxisX.MajorGrid.Enabled = false;
area.AxisY.MajorGrid.Enabled = false;
area.AxisY.MajorTickMark.Enabled = false;
area.AxisY.MinorTickMark.Enabled = false;
area.AxisX.MajorTickMark.Enabled = false;
area.AxisX.MinorTickMark.Enabled = false;
area.BorderWidth = 0;
Chart2.ChartAreas.Add(area);
Series s = new Series(area.Name);
s.ChartType = SeriesChartType.Line;
s.ChartArea = area.Name;
s.Color = System.Drawing.Color.Gray;
foreach (var row in Data)
{
s.Points.AddXY(row.StartDate, row.Sales);
}
Chart2.Series.Add(s);
Any ideas what I'm doing wrong?
Duh. I googled every possible combination of "hide" and "axis" and "line" but didn't Google "asp.net chart control sparklines" until after I posted this.
Answer is here:
http://betterdashboards.wordpress.com/2010/02/21/how-to-create-a-sparkline-chart-in-asp-net/
I was missing setting the LineWidth property on the ChartArea:
area.AxisX.LineWidth = 0;
area.AxisY.LineWidth = 0;
chart1.ChartAreas[0].AxisY.StripLines.Add(new StripLine());
chart1.ChartAreas[0].AxisY.StripLines[0].BackColor = Color.FromArgb(80, 252, 180, 65);
chart1.ChartAreas[0].AxisY.StripLines[0].StripWidth = 40;
chart1.ChartAreas[0].AxisY.StripLines[0].Interval = 10000;
chart1.ChartAreas[0].AxisY.StripLines[0].IntervalOffset = 20;