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?
Related
I'm using the following code to generate a chart:
public ActionResult GenerateChart()
{
var chart = new Chart();
chart.AntiAliasing = AntiAliasingStyles.All;
chart.TextAntiAliasingQuality = TextAntiAliasingQuality.High;
chart.Width = 500;
chart.Height = 400;
ChartArea area = new ChartArea();
area.AxisY.LabelStyle.Format = "{0:c}";
chart.ChartAreas.Add(area);
Series serie = new Series();
serie.ChartType = SeriesChartType.Column;
serie.Points.DataBindXY(data, "Year", data, "Amount");
chart.Series.Add(serie);
using (var stream = new MemoryStream())
{
chart.SaveImage(stream, ChartImageFormat.Jpeg);
return File(stream.ToArray(), "image/jpeg");
}
}
It's a simple column chart with data for a sum of amount (Y-axis) per year (X-axis).
The data variable supplied while testing the code has only 1 item. This item represents year 2015 with an amount of a little bit over 9.000 (no pun intended).
As you can see from the image generated below, despite having data for only 1 year, the chart automatically adds the previous year and the next one.
How can I show only 2015? Or at least hide those points/labels programatically? Why is it adding that information?
Thanks in advance.
Try disabling the margin on the X axis with
area.AxisX.IsMarginVisible = false;
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.
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 quite new to OpenLayers. Right now, I have a polygon vector with some styling applied and a label.
var style = $.extend(true, {}, OpenLayers.Feature.Vector.style['default']);
style.pointRadius = 15;
style.label = "My Polygon";
style.fillColor = #f00;
style.strokeColor = #000;
var styleMap = new OpenLayers.StyleMap({"default" : style});
var polygonLayer = new OpenLayers.Layer.Vector("Polygon Layer", {styleMap: styleMap});
At some point after doing some processing, I want to display the result as a label. How can I update the label? I figure it would be something like this, but this wasn't the way.
polygonLayer.options.styleMap.styles.label = "Updated label";
Thanks in advance.
You are on the right way. You can set new label for all features in a layer like that:
polygonLayer.styleMap.styles.default.defaultStyle.label = "new label";
polygonLayer.redraw();
As you see it's important to call redraw() method after you set new value.
That's how you change label for all features in a layer. Quite often though you'll need to set new labels per feature. To achieve that you should do following when you create pollygonLayer:
var style = $.extend(true, {}, OpenLayers.Feature.Vector.style['default']);
style.label = "${feature_name}";
Each feature has a collection of attributes. In this case value of attribute feature_name will be displayed as a label. To change label value per feature you simply change value of the attribute on that feature and then of course call redraw() on layer.
I have a flex chart that I'm trying to build via actionscript dynamically. For test purposes I came up with the following data structure and code:
Bindable]
public var columnDat:Array=
[{signalID:"SCL", point2:100},
{signalID:"SCL", point2:50},
{signalID:"SCL", point2:30},
{signalID:"SCL", point2:60},
{signalID:"SCL", point2:220},
{signalID:"SCL", point2:140},
{signalID:"SCL", point2:280}];
public function makeDummyChart(genericChart:CartesianChart, genericLegend:Legend, chartPanel:ChartPanel):void {
var renderers:ArrayCollection = new ArrayCollection();
genericChart = new ColumnChart();
// Define the two axes.
var dispAxis:CategoryAxis = new CategoryAxis();
var axr:AxisRenderer = new AxisRenderer();
axr.axis = dispAxis;
renderers.addItem(axr);
var seriesList:ArrayCollection=new ArrayCollection();
// Add the series
genericChart.horizontalAxis = dispAxis;
var columnSeries:ColumnSeries = new ColumnSeries();
BindingUtils.bindProperty(columnSeries, "dataProvider", this, "columnDat");
columnSeries.xField="signalID";;
columnSeries.yField="point2";
seriesList.addItem(columnSeries);
genericChart.series = seriesList.toArray();
genericLegend.dataProvider = genericChart;
genericChart.horizontalAxisRenderers = renderers.toArray();
genericLegend.dataProvider = genericChart;
// chart panel is just the panel on the screen where chart is displayed
chartPanel.addChild(genericChart);
trace (" make dummy chart done");
}
I just get a blank chart when I run this code.
Can't test it by now, but it should be sufficient if you just assign the columnDat array to the series:
columnSeries.dataProvider = columnDat;
or to the column chart:
genericChart.dataProvider = columnDat;
First, you should probably use MXML for this stuff. It's easier.
Second, I don't think you followed the example very well. There's 2 ways of doing charts:
1) Add data to the chart data provider and have the series specify the x and y field within that data provider.
2) Don't add data to the chart and just add the data directly into series without specifying the x and y field.
Right now, you're doing a mix of both 1 and 2 and the series can't see the data because it's being filtered out, which is why it's blank. Don't set the data provider on the series, but set it on the chart instead and it should work. For further example, look at the docs.