Winform chart label wrong position - forms

See Image. The £12,845.63 is 1st columns label. I've tried running below code on a blank, fresh chart, with all default settings (white background too) it does the same thing.
I'm populating chart like this:
private void InitializeData()
{
chart1.Series.Clear();
double i = 0;
double spacing = 0.1;
foreach (DataRow rows in DailyBarChartT.Rows)
{
Series series = chart1.Series.Add(rows[0].ToString());
series.Points.AddXY(i, rows[1]);
series.IsValueShownAsLabel = true;
series.LabelFormat = "C";
series.LabelForeColor = Color.White;
i = i + spacing;
}
chart1.Update();
}
I'm guessing the number doesn't fit above the blue bar? how could I fix this?
I've tried setting label margins to 0 and a few other things.
EDIT:
setting my "spacing" variable to 0, sets the label to correct position.
How can I have it in a correct position with spacing?

You create a new series for every value, which is not how you are supposed to do it. The spacing works properly if you make one single series for all values.
Quick sample code (works on default chart):
string[] values =
{
"12845.63", "1174.89",
"344.04", "180.83",
"82.50", "55.00"
};
chart1.ChartAreas[0].BackColor = Color.Black;
chart1.Series.Clear();
Series series = new Series();
series.IsValueShownAsLabel = true;
series.LabelFormat = "C";
series.LabelForeColor = Color.White;
foreach (var value in values)
{
var pointIndex = series.Points.AddY(value);
series.Points[pointIndex].AxisLabel = "Custom label for each value here";
}
chart1.Series.Add(series);

Related

ChartJS - line graph, position tooltip

I have the following graph with 3 datasets. Everything works fine except for one small bug. I want to tooltip to be placed only on the first dataset, as it currently is placed on the average position of all datasets.
Here is a screenshot:
I know that ChartJS has the positioners function (the one below), but I can't figure out how to ignore the other 2 datasets so the tooltip is sticked only to the first line graph
Chart.Tooltip.positioners.top = function (elements, eventPosition) {
const tooltip = this;
return ;
};
You can also define a custom position function for tooltips. like this,
Chart.Tooltip.positioners.custom = function(elements, eventPosition) {
var x = eventPosition.x;
var y = eventPosition.y;
var minDistance = Number.POSITIVE_INFINITY;
var i, len, nearestElement;
var top_element = elements[0];
for (i = 0, len = elements.length; i < len; ++i) {
console.log(elements[i].tooltipPosition().y);
if (elements[i].tooltipPosition().y < top_element.tooltipPosition().y) {
top_element = elements[i];
}
}
var tp = top_element.tooltipPosition();
x = tp.x;
y = tp.y;
return {
x: x,
y: y
};
};
Once done, you can specify it in tooltips.options.
More information :
https://www.chartjs.org/docs/latest/configuration/tooltip.html#position-modes
Hope it helps!

iTextSharp ColumnText drawing and height not correct

I'm trying to place text into a ColumnText object and calculate its exact height. I'm using iTextSharp 5.5.9
What I'm finding is that there appears to be some "padding" at the top of the ColumnText object and it causes the height calculation to be flawed and the text to be misplaced. I'm trying to understand exactly what's happening - here's my code:
var doc = new Document(PageSize.LETTER, DocumentRenderer.PageMarginSize, DocumentRenderer.PageMarginSize, DocumentRenderer.PageTopMarginSize, DocumentRenderer.PageMarginSize);
doc.SetPageSize(PageSize.LETTER.Rotate());
var writer = PdfWriter.GetInstance(doc, fs);
doc.Open();
var x = 5;
var y = doc.PageSize.Height - 5;
var width = doc.PageSize.Width/ 2;
var height = doc.PageSize.Height - 10;
var lines = new List<string> { "Test string", };// "Test string 2", "Test string 3", "Test string 4" };
for (int i = 0; i < 6; i++)
{
lines.Add("Test String " + i);
}
lines.Add(lines.Aggregate((a, b) => a + ", " + b));
lines.Add(lines.Aggregate((a, b) => a + "\n" + b));
PdfContentByte cb = writer.DirectContent;
cb.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL);
cb.SetCMYKColorFill(DocumentRenderer.DarkColor.C, DocumentRenderer.DarkColor.M, DocumentRenderer.DarkColor.Y, DocumentRenderer.DarkColor.K);
Font ListFont = new Font(DocumentRenderer.TextFont, 12);
ColumnText ct = new ColumnText(cb);
ct.Leading = 14;
//ct.UseAscender = true;
ct.Alignment = Element.ALIGN_LEFT;
ct.SetSimpleColumn(x, y - height, x + width, y);
lines.ForEach(line =>
{
ct.AddText(new Phrase(line + "\n", ListFont));
});
ct.Go();
var height1 = (ct.LinesWritten * ct.Leading);
var height2 = y - ct.YLine;
DocumentRenderer.DrawBox(ref doc, ref writer, new BoxInfo(x, y, width, height2), DocumentRenderer.HighlightColor);
if (doc.IsOpen())
doc.Close();
Here are the results - please note that I highlighted the text with my cursor for effect.
I stumbled into this post (iText placement of Phrase within ColumnText) regarding UseAscender and tried it out by uncommenting that line in the code. You can see that on the right in the picture and it didn't appear to work like I was hoping.
What I really want is the text to still have its leading drawn correctly but for that to start at the top of the ColumnText. Also, I'm trying to get an accurate height for the text. The ct.YLine appears to give me the line at the bottom of the text but the text will overhang below that slightly. I'm not sure why that's not correct but I need to know the exact height if that's possible...
Anyone know how I might achieve these two things?

How target a movieClip in animate cc in this drag drop code

is there a way to modify this code for animate cc to make object in the stage and interact with it ?
it is a bit of pain to make drag and drop in createjs for animate cc
there is nothing in the web that describe how to do it for animate cc or flash cc even the documentation has nothing to tell about drag and drop in the canvas
//Stage
var stage = new createjs.Stage("demoCanvas");
//VARIABLES
//Drag Object Size
dragRadius = 40;
//Destination Size
destHeight = 100;
destWidth = 100;
//Circle Creation
var label = new createjs.Text("DRAG ME", "14px Lato", "#fff");
label.textAlign="center";
label.y -= 7;
var circle = new createjs.Shape();
circle.graphics.setStrokeStyle(2).beginStroke("black")
.beginFill("red").drawCircle(0,0, dragRadius);
//Drag Object Creation
//Placed inside a container to hold both label and shape
var dragger = new createjs.Container();
dragger.x = dragger.y = 100;
dragger.addChild(circle, label);
dragger.setBounds(100, 100, dragRadius*2, dragRadius*2);
//DragRadius * 2 because 2*r = width of the bounding box
var label2 = new createjs.Text("HERE", "bold 14px Lato", "#000");
label2.textAlign = "center";
label2.x += 50;
label2.y += 40;
var box = new createjs.Shape();
box.graphics.setStrokeStyle(2).beginStroke("black").rect(0, 0, destHeight, destWidth);
var destination = new createjs.Container();
destination.x = 350;
destination.y = 50;
destination.setBounds(350, 50, destHeight, destWidth);
destination.addChild(label2, box);
//DRAG FUNCTIONALITY =====================
dragger.on("pressmove", function(evt){
evt.currentTarget.x = evt.stageX;
evt.currentTarget.y = evt.stageY;
stage.update(); //much smoother because it refreshes the screen every pixel movement instead of the FPS set on the Ticker
if(intersect(evt.currentTarget, destination)){
evt.currentTarget.alpha=0.2;
box.graphics.clear();
box.graphics.setStrokeStyle(3)
.beginStroke("#0066A4")
.rect(0, 0, destHeight, destWidth);
}else{
evt.currentTarget.alpha=1;
box.graphics.clear(); box.graphics.setStrokeStyle(2).beginStroke("black").rect(0, 0, destHeight, destWidth);
}
});
//Mouse UP and SNAP====================
dragger.on("pressup", function(evt) {
if(intersect(evt.currentTarget, destination)){
dragger.x = destination.x + destWidth/2;
dragger.y = destination.y + destHeight/2;
dragger.alpha = 1;
box.graphics.clear();
box.graphics.setStrokeStyle(2).beginStroke("black").rect(0, 0, destHeight, destWidth);
stage.update(evt);
}
});
//Tests if two objects are intersecting
//Sees if obj1 passes through the first and last line of its
//bounding box in the x and y sectors
//Utilizes globalToLocal to get the x and y of obj1 in relation
//to obj2
//PRE: Must have bounds set for each object
//Post: Returns true or false
function intersect(obj1, obj2){
var objBounds1 = obj1.getBounds().clone();
var objBounds2 = obj2.getBounds().clone();
var pt = obj1.globalToLocal(objBounds2.x, objBounds2.y);
var h1 = -(objBounds1.height / 2 + objBounds2.height);
var h2 = objBounds2.width / 2;
var w1 = -(objBounds1.width / 2 + objBounds2.width);
var w2 = objBounds2.width / 2;
if(pt.x > w2 || pt.x < w1) return false;
if(pt.y > h2 || pt.y < h1) return false;
return true;
}
//Adds the object into stage
stage.addChild(destination, dragger);
stage.mouseMoveOutside = true;
stage.update();
thanks
I am not exactly sure what you are asking. The demo you showed works fine (looks like it came from this codepen), and it is not clear what you are trying to add. This demo was made directly in code, not with Animate CC - which is really good for building assets, animations, and display list structure, but you should write application code around what gets exported.
There are plenty of documentation and examples online for Drag and Drop, in the EaselJS GitHub, and EaselJS docs:
DragAndDrop demo in GitHub
Live demo on EaselJS demos page
Documentation on pressMove
Tutorial on Mouse Events which includes Drag and Drop
I recommend narrowing down what you are trying to do, show what code or approaches you have tried so far, and posting specific questions here.
Lastly, here is the first part of an ongoing series for working with Animate CC: http://blog.gskinner.com/archives/2015/04/introduction-to-the-flash-cc-html5-canvas-document.html
Cheers.

Unity3D ScrollView/ScrollBar from bottom to top

I'm trying to create a terminal emulator in Unity. I'm able to enter text and have it displayed as output above, and the output will generate a scrollbar when enough text is entered via a ScrollView.
However I can't figure out how to make the scrollbar jump to the bottom when a user enters text.
This is the method used to draw the GUI Window.
// relevant instance variables
private Rect _windowPosition = new Rect();
List<string> output = new List<string>();
string user_input = "";
Vector2 scroll_pos = new Vector2(1,1);
...
...
...
private void onWindow(int windowID){
GUILayout.BeginVertical();
// Output is placed here. Is Scrollable
scroll_pos = GUILayout.BeginScrollView( scroll_pos );
GUILayout.Label( String.Join("\n", output.ToArray()) );
GUILayout.EndScrollView();
// Output ends here. Next piece is user input
user_input = GUILayout.TextField(user_input);
if (Event.current.Equals(Event.KeyboardEvent("return"))) {
output.Add(user_input);
user_input = ""; //clears the TextField
scroll_pos.x = 1;
scroll_pos.y = 1;
}
GUILayout.EndVertical();
GUI.DragWindow();
}
From my searching, I'd seen it said that I should just change the scroll_pos variable, since that's used to control/read the scrollbar's position. The scrollbar's value is normalized between 0 - 1.
I've tried forcing the scroll_pos values to be both, 0 and 1, but it has no impact. Beyond this I'm not sure how to approach the problem.
Try to change
scroll_pos.x = 1;
scroll_pos.y = 1;
to
scroll_pos.y += 9999;
if you want to force scroll on horizontal do it with X too but usually consoles doesn't generates horizontal scroll, they force line breaks based on how many columns you configure.

Flash : How to write roll over coding for grid in array which is similar colour movieclips nearby?

Flash AS3:
I just need to know how to check a condition for roll over effect on similar colour movieclips which is near by in a group of random colours movieclips in a grid whereas it is using 2D Array in flash AS3.or
I just need roll over event which i wrote is onBoxOver event function, in that the object which i am targetting is only getting rollover or getting alpha changes. But i need to know how to make rollover for similar colour which are all nearby.
The code which i wrote is below for your reference.
Flash AS3::
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class playGame extends MovieClip
{
public static var totalRowBoxes:Number = 13;
public static var totalColumnBoxes:Number = 12;
public static var rowGap:Number = 30;
public static var columnGap:Number = 30;
public static var totalColorBoxes:Number = 8;
public static var boxCollection:Array = new Array();
public static var boxCollection1:Array = new Array();
public function playGame(theGame:main)
{
// constructor code
addBoxOnStage();
}
private function addBoxOnStage():void
{
var borderCont:Banner = new Banner();
var scoreclipCont:scoreclip = new scoreclip();
addChild(borderCont);
addChild(scoreclipCont);
scoreclipCont.x = 0;
scoreclipCont.y = 0;
createLevel(1);
for (var i:Number = 0; i<totalRowBoxes; i++)
{
boxCollection[i] = new Array(i);
for (var j:Number = 0; j<totalColumnBoxes; j++)
{
var squareCont:square = new square();
squareCont.x = 30 + (i * rowGap);
squareCont.y = 30 + (j * columnGap);
squareCont.name = i + "_" + j;
var boxCollection1:Array = new Array();
boxCollection1[0] = Math.round(Math.random() * 8);
boxCollection1[1] = squareCont;
var boxColour:Number = new Number();
boxColour = boxCollection1[0];
boxCollection[i][j] = boxCollection1[1];
addChild(squareCont);
squareCont.gotoAndStop(boxCollection1[0]);
squareCont.addEventListener(MouseEvent.MOUSE_OVER, onBoxOver); squareCont.addEventListener(MouseEvent.MOUSE_OUT, onBoxOut);
squareCont.addEventListener(MouseEvent.CLICK, onBoxClick);
}
}
}
private function onBoxClick(eve:MouseEvent):void
{
}
private function onBoxOver(eve:MouseEvent):void
{
for (var i:Number=0; i< totalRowBoxes; i++)
{
for (var j:Number=0; j<totalColumnBoxes; j++)
{
eve.target.alpha = 0.3;
// trace(boxCollection[i][j].currentFrame)
trace(eve.target);
}
}
}
private function onBoxOut(eve:MouseEvent):void
{
eve.target.alpha = 1;
}
private function createLevel(lvl):void
{
}
}
}
![My Game screenshot here colourbox][1]
Thanks in Advance. Greatly Appreciable for the reply.
Hi this is the image or screenshot of my project. In that image there are 8 colours randomly arranged. whenever i make mouse position or rollover on any box , the condition should check whether the same colour occurs around the box(eg.top, down, left, right) which i am making rollover.
1.If the same colour occur on the top of the box which i am pointing the cursor , the top box and the box which i am pointing both should get less alpha, else only the pointing box should get less alpha. this is my concept friends. please go through the image and let me know if u have any doubts.
I am still unsure what you mean by 'nearby'. (neighbour tiles? adjacent of similar colour?...)
If 'nearby' means adjacent, you need to read about flood fill algorithms. There is a good wiki article about this. You would use that to crawl through the list of tiles similar enough to trigger the effect you want.
I also don't know what 'similar' colour means in your project. You will need a method to determine weather two colours are similar. There is a stackoverflow question re: similar colour detection. It has a good answer to start you out in your research. look here.