Heat series graph: order in gradient bar - c#

I am new to livechart and I have made the following basic graphic in livechart. However, I have 2 doubts about it.
using System;
using System.Windows.Forms;
using System.Windows.Media;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
namespace heatmap
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var converter = new System.Windows.Media.BrushConverter();
var brush = (Brush)converter.ConvertFromString("#000000");
var r = new Random();
cartesianChart1.Series.Add(new HeatSeries
{
Values = new ChartValues<HeatPoint>
{
new HeatPoint(0, 0, 0.25),
new HeatPoint(0, 1, 0.5),
new HeatPoint(0, 2, 0.5),
new HeatPoint(0, 3, 1),
new HeatPoint(1, 0, 0.5),
new HeatPoint(1, 1, 0.5),
new HeatPoint(1, 2, 1),
new HeatPoint(1, 3, 0.5),
//"Robyn Williamson"
new HeatPoint(2, 0, 0.5),
new HeatPoint(2, 1, 1),
new HeatPoint(2, 2, 0.5),
new HeatPoint(2, 3, 0.5),
new HeatPoint(3, 0, 1),
new HeatPoint(3, 1, 0.5),
new HeatPoint(3, 2, 0.25),
new HeatPoint(3, 3, 0.25),
},
Fill=brush,
Stroke=brush,
Foreground = brush,
FontSize=20,
DataLabels = true,
// LabelPoint=val=>"hola",
//The GradientStopCollection is optional
//If you do not set this property, LiveCharts will set a gradient
GradientStopCollection = new GradientStopCollection
{
new GradientStop(Color.FromRgb(255, 255, 255), 0),
new GradientStop(Color.FromRgb(0, 255, 0), .25),
new GradientStop(Color.FromRgb(7, 193, 67), .5),
new GradientStop(Color.FromRgb(0, 128, 0), .75),
new GradientStop(Color.FromRgb(0, 60, 31), 1),
},
});
cartesianChart1.AxisX.Add(new Axis
{
Position = AxisPosition.RightTop,
LabelsRotation = 0,
FontSize=15,
Labels = new[]
{
"variable rent",
"int tax.",
"Real state",
"money"
},
Separator = new Separator { Step = 1 }
});
cartesianChart1.AxisY.Add(new Axis
{
FontSize = 15,
Labels = new[]
{
"Money",
"Real state",
"int tax",
"variable rent"
}
});
}
}
}
Output:
How can you reverse the order of the gradient bar? 1 in the top and 0.25 in bottom.
Is it possible for each HeatPoint to place a tooltip or a color for each label(1 label white and other label yellow)?
thanks to all

Related

How to implement Breadth First Search (BFS) algorithm in a .NET application to find a path from point to another point?

This is related to my question yesterday regarding how to approach this problem. I learned useful concepts from the answers but I am unable to adapt the theory to the coding. This is for a system routing application. The simplified version of the issue: I would like to find all of the lines from Point A to E. Result: L1, L3, L6, L7, L8 based on the graphic above.
I would like to have all possible paths but most of the time, there is only 1 possible path.
A to E is the same as E to A so which direction is not important but the order of the lines from the returned solution is important for tracing purposes.
I show a WinForm sample but I do not need a graphical solution. It is for the demonstration purpose.
From the help, I know I need to implement a graph with BFS algorithm. I tried to implement this example https://www.geeksforgeeks.org/print-paths-given-source-destination-using-bfs/ but I got stuck on how to implement the method that input is List<Line> instead of List<integer> from the example.
List<List<Line>> FindPaths(List<Line> InputLines, Point src, Point des)
{
}
// var A = myList[0].P1;
// var E = myList[7].P2;
// var paths = FindPaths(myList,A, E);
I have Line class
public class Line
{
public string Name { get; set; }
public Point P1 { get; set; }
public Point P2 { get; set; }
public Line(string name, Point p1, Point p2)
{
Name = name;
P1 = p1;
P2 = p2;
}
}
and points, lines, and are defined as following
List<Line> myList;
private void DrawSample()
{
//Point definitions
var L1_P1 = new Point(40, 40); //Point A
var L1_P2 = new Point(100, 100);
var L2_P1 = new Point(100, 100);
var L2_P2 = new Point(40, 160); //Point B
var L3_P1 = new Point(100, 100);
var L3_P2 = new Point(180, 100);
var L4_P1 = new Point(180, 100);
var L4_P2 = new Point(180, 25); //Point C
var L5_P1 = new Point(180, 100);
var L5_P2 = new Point(220, 165); //Point D
var L6_P1 = new Point(180, 100);
var L6_P2 = new Point(260, 100);
var L7_P1 = new Point(260, 100);
var L7_P2 = new Point(350, 100);
var L8_P1 = new Point(350, 100);
var L8_P2 = new Point(480, 100);//Point E
//Line definitions
var L1 = new Line("L1", L1_P1, L1_P2);
var L2 = new Line("L2", L2_P1, L2_P2);
var L3 = new Line("L3", L3_P1, L3_P2);
var L4 = new Line("L4", L4_P1, L4_P2);
var L5 = new Line("L5", L5_P1, L5_P2);
var L6 = new Line("L6", L6_P1, L6_P2);
var L7 = new Line("L7", L7_P1, L7_P2);
var L8 = new Line("L8", L8_P1, L8_P2);
myList = new List<Line>();
myList.Add(L1);
myList.Add(L2);
myList.Add(L3);
myList.Add(L4);
myList.Add(L5);
myList.Add(L6);
myList.Add(L7);
myList.Add(L8);
//Graphic
var brush = new SolidBrush(Color.Blue);
var pen = new Pen(Color.Black, 2);
//panelCanvas is just a WinForm Panel
var canvas = panelCanvas.CreateGraphics();
canvas.DrawLine(pen, L1.P1, L1.P2); //L1
canvas.DrawLine(pen, L2.P1, L2.P2); //L2
canvas.DrawLine(pen, L3.P1, L3.P2); //L3
canvas.DrawLine(pen, L4.P1, L4.P2); //L4
canvas.DrawLine(pen, L5.P1, L5.P2); //L5
canvas.DrawLine(pen, L6.P1, L6.P2); //L6
canvas.DrawLine(pen, L7.P1, L7.P2); //L7
canvas.DrawLine(pen, L8.P1, L8.P2); //L8
canvas.DrawString("L1", new Font("Tohoma", 10), brush, 70, 50);
canvas.DrawString("L2", new Font("Tohoma", 10), brush, 70, 140);
canvas.DrawString("L3", new Font("Tohoma", 10), brush, 132, 80);
canvas.DrawString("L4", new Font("Tohoma", 10), brush, 184, 60);
canvas.DrawString("L5", new Font("Tohoma", 10), brush, 180, 135);
canvas.DrawString("L6", new Font("Tohoma", 10), brush, 220, 80);
canvas.DrawString("L7", new Font("Tohoma", 10), brush, 300, 80);
canvas.DrawString("L8", new Font("Tohoma", 10), brush, 420, 80);
//Markings
canvas.DrawString("X", new Font("Tohoma", 10, FontStyle.Bold), brush, 94, 92);
canvas.DrawString("X", new Font("Tohoma", 10, FontStyle.Bold), brush, 174, 92);
canvas.DrawString("X", new Font("Tohoma", 10, FontStyle.Bold), brush, 260, 92);
canvas.DrawString("X", new Font("Tohoma", 10, FontStyle.Bold), brush, 350, 92);
canvas.DrawString("A", new Font("Tohoma", 10, FontStyle.Bold), new SolidBrush(Color.Red), 32, 25);
canvas.DrawString("B", new Font("Tohoma", 10, FontStyle.Bold), new SolidBrush(Color.Red), 40, 160);
canvas.DrawString("C", new Font("Tohoma", 10, FontStyle.Bold), new SolidBrush(Color.Red), 174, 10);
canvas.DrawString("D", new Font("Tohoma", 10, FontStyle.Bold), new SolidBrush(Color.Red), 220, 165);
canvas.DrawString("E", new Font("Tohoma", 10, FontStyle.Bold), new SolidBrush(Color.Red), 480, 92);
}
There's a great example using a HashSet and Queue method here: https://www.koderdojo.com/blog/breadth-first-search-and-shortest-path-in-csharp-and-net-core
using System.Collections.Generic;
namespace KoderDojo.Examples {
public class Algorithms {
public HashSet<T> BFS<T>(Graph<T> graph, T start) {
var visited = new HashSet<T>();
if (!graph.AdjacencyList.ContainsKey(start))
return visited;
var queue = new Queue<T>();
queue.Enqueue(start);
while (queue.Count > 0) {
var vertex = queue.Dequeue();
if (visited.Contains(vertex))
continue;
visited.Add(vertex);
foreach(var neighbor in graph.AdjacencyList[vertex])
if (!visited.Contains(neighbor))
queue.Enqueue(neighbor);
}
return visited;
}
}
}

Sharpdx D3D9 nothing draw

I try to follow their examples on github and i just want to draw a line. But when the window opens, there only a blackscreen. I dont know what i did wrong.
Here is my source code.
Thank you for helping !
static void Main()
{
var form = new RenderForm("Test");
int width = form.ClientSize.Width;
int height = form.ClientSize.Height;
var device = new Device(new Direct3D(), 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters(width, height) { PresentationInterval = PresentInterval.One });
Line line = new Line(device);
RawVector2[] vertices =
{
new RawVector2(10, 10),
new RawVector2(10, 10)
};
RenderLoop.Run(form, () =>
{
device.Clear(ClearFlags.Target, new RawColorBGRA(0, 0, 0, 1), 1.0f, 0);
device.BeginScene();
line.Width = 10;
line.GLLines = true;
line.Antialias = false;
line.Draw(vertices, new RawColorBGRA(254, 254, 254, 1));
device.EndScene();
device.Present();
});
}
This might not be your error but it won't help matters because even if there are no errors you will see very little. I have used it but only in a window context and I followed https://github.com/Dan6040/SharpDX-Rastertek-Tutorials because I was coming from C++ Unreal, Raw DX9, and C# Unity, XNA framework.
Your vertices are drawing a 1-pixel dot because you need 2 vectors at different locations to draw a line
[
new RawVector2(10, 10),
new RawVector2(10, 10)
]
That is saying draw from x:10 y:10 to x:10 y:10
try:
[
new RawVector2(10, 10),
new RawVector2(30, 30)
]
So to better explain to draw a triangle you need 3 points and 3 lines, but to draw each line you need points in your ordering
[
new RawVector2(10, 10),
new RawVector2(10, 30),
new RawVector2(30, 30),
new RawVector2(10, 10)
]
So that works by saying draw from 10,10 to 10,30 then to 30,30 and finally back to 10,10
Just to note this is why Games engines don't work through arrays of points they are arrays of pointers to points so you only have the point objects in memory once and you just using pointers to them E.G
static void Main()
{
var form = new RenderForm("Test");
int width = form.ClientSize.Width;
int height = form.ClientSize.Height;
var device = new Device(new Direct3D(), 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters(width, height) { PresentationInterval = PresentInterval.One });
Line line = new Line(device);
RawVector2[] TrianglePoints=
{
new RawVector2(10, 10),
new RawVector2(10, 30),
new RawVector2(30, 30)
};
RawVector2[] vertices = {
TrianglePoints[0],
TrianglePoints[1],
TrianglePoints[2],
TrianglePoints[0]
}
RenderLoop.Run(form, () =>
{
device.Clear(ClearFlags.Target, new RawColorBGRA(0, 0, 0, 1), 1.0f, 0);
device.BeginScene();
line.Width = 10;
line.GLLines = true;
line.Antialias = false;
line.Draw(vertices, new RawColorBGRA(254, 254, 254, 1));
device.EndScene();
device.Present();
});
}

Geometry Gym C# - How to modify existing IFC file with new component?

My requirement is to read an existing IFC file with GeometryGym and add a new object to it. So I've written a C# code as follow,
public void CreateDocuemntRefIcon(string filePath)
{
DatabaseIfc db = new DatabaseIfc(filePath);
IfcProject project = db.Project;
List<IfcBuilding> buildings = project.Extract<IfcBuilding>();
IfcBuilding thisBuilding = buildings.FirstOrDefault();
//Creating cube object
List<Coord3d> points = new List<Coord3d>() {
new Coord3d(0, 0, 0), new Coord3d(10, 0, 0),
new Coord3d(10, 10, 0), new Coord3d(0, 10, 0),
new Coord3d(0, 0, 10), new Coord3d(10, 0, 10),
new Coord3d(10, 10, 10), new Coord3d(0, 10, 10) };
IfcCartesianPointList3D cartesianPointList3D = new IfcCartesianPointList3D(db, points);
List<CoordIndex> coordIndex = new List<CoordIndex>() {
new CoordIndex(1, 6, 5), new CoordIndex(1, 2, 6), new CoordIndex(6, 2, 7),
new CoordIndex(7, 2, 3), new CoordIndex(7, 8, 6), new CoordIndex(6, 8, 5),
new CoordIndex(5, 8, 1), new CoordIndex(1, 8, 4), new CoordIndex(4, 2, 1),
new CoordIndex(2, 4, 3), new CoordIndex(4, 8, 7), new CoordIndex(7, 3, 4)
};
IfcTriangulatedFaceSet triangulatedFaceSet = new IfcTriangulatedFaceSet(cartesianPointList3D, true, coordIndex);
IfcColourRgbList colourRgbList = new IfcColourRgbList(db, new List<Color>() { Color.Red, Color.Green, Color.Yellow });
IfcIndexedColourMap indexedColourMap = new IfcIndexedColourMap(triangulatedFaceSet, colourRgbList, new List<int>() { 1, 1, 2, 2, 3, 3, 1, 1, 1, 1, 1, 1 });
IfcBuildingElementProxy buildingElementProxy =
new IfcBuildingElementProxy(thisBuilding, null, new IfcProductDefinitionShape(new IfcShapeRepresentation(triangulatedFaceSet)));
//Writed the file
db.WriteFile(string.Format("{0}.ifc", "EditedIFC"));
}
This is working well with IFC4 release. But not working for IFC2x3 release. What could be the issue ?
IFC2X3 has no IfcTriangulatedFaceSet. This has been added with IFC4.
You can emulate triangulated surfaces with IfcShellBasedSurfaceModel under IFC2X3.

Misalignment of two chart areas

I was trying to overlap two chart areas. They would share the same x values, but Y would have different values and scales.
Here is outcome of my code:
As you can see red series is not in alignment with green series.I was searching this site for answers, but couldn't find one that worked. Could someone explain me why they don't align?
Code:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace TestGraph
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
#region Data
// Creating first series
Series s1 = new Series();
s1.Name = "Values";
s1.ChartType = SeriesChartType.Column;
s1.XValueType = ChartValueType.DateTime;
s1.Color = Color.Green;
s1.BorderWidth = 2;
// Hard Coding test values
DataPoint[] values =
{
new DataPoint(new DateTime(2017, 8, 1).ToOADate(), 10),
new DataPoint(new DateTime(2017, 8, 2).ToOADate(), 11),
new DataPoint(new DateTime(2017, 8, 3).ToOADate(), 12),
new DataPoint(new DateTime(2017, 8, 4).ToOADate(), 13),
};
// Adding vales to s1
foreach (DataPoint p in values)
{
s1.Points.Add(p);
}
// Creating second series
Series s2 = new Series();
s2.Name = "Values 2";
s2.ChartType = SeriesChartType.Column;
s2.XValueType = ChartValueType.DateTime;
s2.Color = Color.Red;
s2.BorderWidth = 2;
// Hard Coding test values
DataPoint[] values2 =
{
new DataPoint(new DateTime(2017, 8, 1).ToOADate(), 0.1),
new DataPoint(new DateTime(2017, 8, 2).ToOADate(), -0.2),
new DataPoint(new DateTime(2017, 8, 3).ToOADate(), -0.7),
new DataPoint(new DateTime(2017, 8, 4).ToOADate(), 13),
};
// Adding vales to s2
foreach (DataPoint p in values2)
{
s2.Points.Add(p);
}
#endregion
#region Charts
// Initializing chart
Chart mainChart = new Chart();
ChartArea area = new ChartArea();
ChartArea area2 = new ChartArea();
Controls.Add(mainChart);
mainChart.Dock = DockStyle.Fill;
// Adding areas to mainChart
mainChart.ChartAreas.Add(area);
mainChart.ChartAreas.Add(area2);
// Adding series to areas
s1.ChartArea = area.Name;
s2.ChartArea = area2.Name;
mainChart.Series.Add(s1);
mainChart.Series.Add(s2);
// Aligning areas
// Overlapping area2 with area
area2.AlignmentStyle = AreaAlignmentStyles.All;
area2.AlignmentOrientation = AreaAlignmentOrientations.All;
area2.AlignWithChartArea = area.Name;
// Scale actualization
area2.RecalculateAxesScale();
area.RecalculateAxesScale();
// Defining Y scale
area2.AxisY.Maximum = 2;
area2.AxisY.Minimum = -2;
area2.BackColor = Color.Transparent;
// Disabling unnecessary graphics
area2.BackGradientStyle = GradientStyle.None;
area2.AxisX.IsMarginVisible = false;
area2.AxisX.LabelStyle.Enabled = false;
area2.AxisY.LabelStyle.Enabled = false;
area2.AxisX.Enabled = AxisEnabled.False;
area2.AxisY.Enabled = AxisEnabled.False;
// Resizing chart back to 100%
area.Position = new ElementPosition(0, 0, 100, 100);
#endregion
}
}
}
One of your chart has AxisX.IsMarginVisible set to true, the other to false, hence the mismatch.
However, if you are trying to plot overlapping series, why are you not adding them to the same chart area instead of going through all this trouble?

ZedGraph filling areas

I am using the ZedGraph control and want to fill one side of the graph function with some color and other side with other color.
PointPairList list1 = new PointPairList();
list1.Add(0, 4);
list1.Add(4, 0);
LineItem myCurve = myPane.AddCurve("y(n)", list1, Color.Red, SymbolType.Diamond);
//This filling bottom side.
myCurve.Line.Fill = new Fill(Color.White, Color.FromArgb(113, 255, 0, 0), 90F);
//How to fill the top side?
I'm not very clear on what you're asking - but hopefully the below will help. You said in comments
Can I fill some polygon area in Zedgraph?
So here's how...
var zed = new ZedGraph.ZedGraphControl { Dock = System.Windows.Forms.DockStyle.Fill };
var poly = new ZedGraph.PolyObj
{
Points = new[]
{
new ZedGraph.PointD(0, 0),
new ZedGraph.PointD(0.5, 1),
new ZedGraph.PointD(1, 0.5),
new ZedGraph.PointD(0, 0)
},
Fill = new ZedGraph.Fill(Color.Blue),
ZOrder = ZedGraph.ZOrder.E_BehindCurves
};
var poly1 = new ZedGraph.PolyObj
{
Points = new[]
{
new ZedGraph.PointD(1, 0),
new ZedGraph.PointD(0.25, 1),
new ZedGraph.PointD(0.5, 0),
new ZedGraph.PointD(1, 0)
},
Fill = new ZedGraph.Fill(Color.Red),
ZOrder = ZedGraph.ZOrder.E_BehindCurves
};
zed.GraphPane.AddCurve("Line", new[] { 0.0, 1.0 }, new[] { 0.0, 1.0 }, Color.Green);
zed.GraphPane.GraphObjList.Add(poly1);
zed.GraphPane.GraphObjList.Add(poly);
Results in
Hopefully this will point you in the right direction!
(Code in VB as requested via http://converter.telerik.com/ - no guarentee of the VB code working or even compiling!)

Categories

Resources