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;
Related
So I'm new to InDesign CC scripting, but I really just need a very simple solution, or at least I hope that it's a simple solution. I have a script for adding a watermark to a document for export, however i'd like it to be on two lines and take up more space on the page rather than just one line. Below is the script I'm using:
var myDoc = app.activeDocument,
myPdfExportPreset = "[High Quality Print]",
myPdfFile = File(myDoc.fullName.fsName.replace(/.indd$/i, "") + ".pdf");
app.scriptPreferences.measurementUnit = MeasurementUnits.INCHES
var docHeight = myDoc.documentPreferences.pageHeight
var docWidth = myDoc.documentPreferences.pageWidth
with(myDoc.watermarkPreferences)
{
watermarkVisibility = true;
watermarkDoPrint = true;
watermarkDrawInBack = false;
watermarkText = "I would like the code to split between the word split and between";
watermarkFontFamily = "Helvetica";
watermarkFontStyle = "Bold";
watermarkFontPointSize = Math.round(docWidth * 7);
watermarkFontColor = [0, 0, 0];
watermarkOpacity = 15;
watermarkRotation = -25;
watermarkHorizontalPosition = WatermarkHorizontalPositionEnum.watermarkHCenter;
watermarkHorizontalOffset = 0;
watermarkVerticalPosition = WatermarkVerticalPositionEnum.watermarkVCenter;
watermarkVerticalOffset = 0;
}
If anyone has an idea on how to insert a line break, I'm not sure if it's like html where you can just <br> and be done with it, but that's kind of what I'm looking for, if that makes sense. Thanks so much in advance!
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.
I am working with System.Web.UI.DataVisualization.Charting to create some line charts. I want to show tooltips(x and y value of the datapoint) when mouse over on a data point of a series.
As shown in the chart image, i want a tooltip when mouse is hovered on the red circle.
chart image
I added series.ToolTip method but , its not working.
here is my createSeries meothod
private System.Web.UI.DataVisualization.Charting.Series CreateSeries(List<X> xAxisData, List<Y> yAxisdata)
{
// Chart Series
System.Web.UI.DataVisualization.Charting.Series _series =
new System.Web.UI.DataVisualization.Charting.Series(this.SeriesNameList[this.seriesCount]);
_series.ChartType = this.ChartType;
// Bind the data
_series.Points.DataBindXY(xAxisData, yAxisdata);
// Set Default Properties
_series.Font = this.GetFontForSeries();
_series.LabelForeColor = this.GetLabelColor();
// Add Transparent Marker to increase mouse area for ToolTip
_series.MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Circle;
_series.MarkerSize = 7;
_series.ToolTip = "hello";
//// Smart Labels
_series.SmartLabelStyle.Enabled = true;
_series.SmartLabelStyle.MinMovingDistance = 5;
_series.SmartLabelStyle.MaxMovingDistance = 50;
_series.SmartLabelStyle.MovingDirection =
System.Web.UI.DataVisualization.Charting.LabelAlignmentStyles.Top |
System.Web.UI.DataVisualization.Charting.LabelAlignmentStyles.TopLeft |
System.Web.UI.DataVisualization.Charting.LabelAlignmentStyles.TopRight |
System.Web.UI.DataVisualization.Charting.LabelAlignmentStyles.Bottom |
System.Web.UI.DataVisualization.Charting.LabelAlignmentStyles.BottomLeft |
System.Web.UI.DataVisualization.Charting.LabelAlignmentStyles.BottomRight |
System.Web.UI.DataVisualization.Charting.LabelAlignmentStyles.Left |
System.Web.UI.DataVisualization.Charting.LabelAlignmentStyles.Right |
System.Web.UI.DataVisualization.Charting.LabelAlignmentStyles.Center;
_series.SmartLabelStyle.IsOverlappedHidden = true;
_series.SmartLabelStyle.AllowOutsidePlotArea = System.Web.UI.DataVisualization.Charting.LabelOutsidePlotAreaStyle.Yes;
this.seriesCount++;
return _series;
}
private void InitializeChart()
{
this.Chart.IsMapEnabled = false;
this.Chart.RenderType = System.Web.UI.DataVisualization.Charting.RenderType.ImageTag;
this.Chart.ImageType = System.Web.UI.DataVisualization.Charting.ChartImageType.Png;
this.Chart.AntiAliasing = System.Web.UI.DataVisualization.Charting.AntiAliasingStyles.Graphics;
this.Chart.TextAntiAliasingQuality = System.Web.UI.DataVisualization.Charting.TextAntiAliasingQuality.High;
this.CreateTitle();
this.CreateLegends();
}
Can someone help me ?
I searched through some of the questios but couldn't find a solution.
You need to add the tooltip to the points.
Points.DataBindXY does not have a way of binding extended chart properties like tooltips. (Points.DataBind appears to, btw)
Source: http://blogs.msdn.com/b/alexgor/archive/2009/02/21/data-binding-ms-chart-control.aspx
So a workaround is to loop through your series points and add the tooltip manually to the points. You can do so using / modifying the code below. (#VALX and #VAL is one way of adding the XY coordinate without directly reading the value, another way would be to read the XY values directly)
// Bind the data
_series.Points.DataBindXY(xAxisData, yAxisdata);
// Set Tooltips
foreach(var point in _series.Points)
{
point.ToolTip = "(#VALX, #VAL)";
}
// Set Default Properties
_series.Font = this.GetFontForSeries();
_series.LabelForeColor = this.GetLabelColor();
Alternate way not using keywords:
// Bind the data
_series.Points.DataBindXY(xAxisData, yAxisdata);
// Set Tooltips
foreach(var point in _series.Points)
{
point.ToolTip = "(" + point.X + ", " + point.YValues[0] + ")";
}
// Set Default Properties
_series.Font = this.GetFontForSeries();
_series.LabelForeColor = this.GetLabelColor();
I'm looking for a way to use framecloud type popup with my current setup. Unfortunately all my attempts have either not worked or will only work on the most recently placed maker.
In the course of trying to get it to work I have converted my original script from using Markers to using Vectors to placing the marker points (as I've seen that it's easier to customize vectors than markers.)
Now which ever one I can get to work I'll use, but after working on this for a few days I'm at my wits end and need a helping hand in the right direction.
My points are pulled from a google spreadsheet using tabletop.js. The feature is working how I wish it to, with the markers being placed on their respective layer based on a field I called 'type'.
While I have a feeling that might have been the source of my problem with the Markers type layer, I'm not sure how to fix it.
You can view the coding through these pages
(Links removed due to location change.)
Thanks for all help in advance.
I finally got it to work. For anyone in a similar situation here's my final code for the layers. I did change the names of the layers from what they are originally and blacked out the spreadsheet I used, but the changes should be noticeable.
//
//// Set 'Markers'
//
var iconMarker = {externalGraphic: 'http://www.openlayers.org/dev/img/marker.png', graphicHeight: 21, graphicWidth: 16};
var iconGeo = {externalGraphic: './images/fortress.jpg', graphicHeight: 25, graphicWidth: 25};
var iconAero = {externalGraphic: './images/aeropolae.jpg', graphicHeight: 25, graphicWidth: 25}; // Image is the creation of DriveByArtist: http://drivebyartist.deviantart.com/
var vector1 = new OpenLayers.Layer.Vector("1");
var vector2 = new OpenLayers.Layer.Vector("2");
var vector3 = new OpenLayers.Layer.Vector("3");
// Pulls map info from Spreadsheet
//*
Tabletop.init({
key: 'http://xxxxxxxxxx', //Spreadsheet URL goes here
callback: function(data, tabletop) {
var i,
dataLength = data.length;
for (i=0; i<dataLength; i++) { //following are variables from the spreadsheet
locName = data[i].name;
locLon = data[i].long;
locLat = data[i].lat;
locInfo = data[i].info;
locType = data[i].type; // Contains the following string in the cell, which provides a pre-determined output based on provided information in the spreadsheet: =ARRAYFORMULA("<h2>"&B2:B&"</h2><b>"&G2:G&"</b><br /> "&C2:C&", "&D2:D&"<br />"&E2:E&if(ISTEXT(F2:F),"<br /><a target='_blank' href='"&F2:F&"'>Read More...</a>",""))
locLonLat= new OpenLayers.Geometry.Point(locLon, locLat);
switch(locType)
{
case "Geopolae":
feature = new OpenLayers.Feature.Vector(
locLonLat,
{description:locInfo},
iconGeo);
vector1.addFeatures(feature);
break;
case "POI":
feature = new OpenLayers.Feature.Vector(
locLonLat,
{description:locInfo},
iconMarker);
vector2.addFeatures(feature);
break;
case "Aeropolae":
feature = new OpenLayers.Feature.Vector(
locLonLat,
{description:locInfo},
iconAero);
vector3.addFeatures(feature);
break;
}
}
},
simpleSheet: true
});
map.addLayers([vector1, vector2, vector3]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
//Add a selector control to the vectorLayer with popup functions
var controls = {
selector: new OpenLayers.Control.SelectFeature(Array(vector1, vector2, vector3), { onSelect: createPopup, onUnselect: destroyPopup })
};
function createPopup(feature) {
feature.popup = new OpenLayers.Popup.FramedCloud("pop",
feature.geometry.getBounds().getCenterLonLat(),
null,
'<div class="markerContent">'+feature.attributes.description+'</div>',
null,
true,
function() { controls['selector'].unselectAll(); }
);
feature.popup.autoSize = true;
feature.popup.minSize = new OpenLayers.Size(400,100);
feature.popup.maxSize = new OpenLayers.Size(400,800);
feature.popup.fixedRelativePosition = true;
feature.popup.overflow ="auto";
//feature.popup.closeOnMove = true;
map.addPopup(feature.popup);
}
function destroyPopup(feature) {
feature.popup.destroy();
feature.popup = null;
}
map.addControl(controls['selector']);
controls['selector'].activate();
}
My question is at the very end of the post.
I have tried everything from setting a timer for all the markers to be set to all kinds of calculations of the four corners, but nothing seems to be working.
Each time that I add a marker to the markermanager, I call this function below
public function markerSetBounds(someLat , someLng):void{
var bounds:LatLngBounds = new LatLngBounds();
for(var i:int = 0; i < myMarkers.length; i++)
{
var currentLatLon:LatLng = new LatLng(someLat , someLng);
bounds.extend(currentLatLon);
}
googleMap.setZoom(googleMap.getBoundsZoomLevel(bounds));
googleMap.setCenter(bounds.getCenter());
}
I believe I know why this does not work. I am only sending one set of lat, lng at a time.
However, when I tried the following, flex told me that it did not know what myMarkers[i].lat meant.
The following is how I fill myMarkers array
var someMarker:Marker = new Marker(new LatLng(someLat , someLng), new MarkerOptions({tooltip:someAddress, hasShadow: true}));
myMarkers.push(someMarker);
This is how I want to traverse through the array, but flex does not understand what .lat means.
for(var i:int = 0; i < myMarkers.length; i++)
{
var currentLatLon:LatLng = new LatLng(myMarkers[i].lat , myMarkers[i].lng);
bounds.extend(currentLatLon);
}
My question is how do I traverse through the myMarkers array to set currentLatLon. I have also tried a for each(var someObj:Marker in myMarkers) but it finds nothing. The markers are showing up on the map, but the bounds are not working.
Have you tried doing something like:
(myMarkers[i] as Marker).lat
Is this a problem at run time or compile time?
OK, I figured out was what the issue and it was that I had to place things in the correct order.
First, declare the LatLngBounds.
Second, make the markers.
Third, set the zoom
Forth, extend the bounds.
bounds = new LatLngBounds();
covToXML = new XML(event.result);
xmlToList = new XMLList(covToXML);
listToCol = new XMLListCollection(xmlToList);
someLat = Number(listToCol.children().child("geometry").child("location").child("lat").text());
someLng = Number(listToCol.children().child("geometry").child("location").child("lng").text());
someAddress = String(listToCol.children().child("formatted_address").text());
var markerOptions:MarkerOptions = new MarkerOptions();
markerOptions.icon = new (whichIcon(GlobalVars.randomIcon));
markerOptions.tooltip = someAddress;
markerOptions.hasShadow = true;
someMarker = new Marker(new LatLng(someLat , someLng), markerOptions);
someMarker.addEventListener(MapMouseEvent.CLICK,markerClicked);
myMarkers.push(someMarker);
googleMap.addOverlay(someMarker);
for each(someMarker in myMarkers)
{
var newLatLng:LatLng = someMarker.getLatLng();
// Alert.show(newLatLng.toString());
bounds.extend(newLatLng);
}
googleMap.setCenter(bounds.getCenter());
googleMap.setZoom(googleMap.getBoundsZoomLevel(bounds));
Thanks for all the suggestions and questions, which helped me to the solution.