How can format the labels in mschart so that it contains X-Value and other value from database like this:
12 KG , 200 POUND , 45 LIters
lets call it the MeasureUnit value and it is deffirent with each X-Value
help me please
I tried this but the label appears as 0 always
Chart1.Series(0).Points.DataBind(Data, XValue, YValue, "Label=" & YValue & ControlChars.Lf & LabelUnit)
Here is the Ans:
Chart1.Series(0).Points.DataBind(Data, XValue, YValue, "Unit=" & LabelUnit)
Chart1.Series("Series1").XValueMember = XValue
Chart1.Series("Series1").YValueMembers = YValue
For Each pnt As DataPoint In Chart1.Series(0).Points
pnt.Label = "#VAL" & ControlChars.Lf & pnt.GetCustomProperty("Unit")
Next
Chart1.Series("Series1").IsValueShownAsLabel = True
Chart1.Series("Series1").ToolTip = "#VAL"
You can use AxisLabel property
chart1.Series[i].Points[i].AxisLabel = yourValue; // here yourValue is the value returned by database
OR if your series already has data you can do
foreach (DataPoint dp in s.Points)
{
dp.AxisLabel = dp.XValue + "yourUnit" ; // or write your own logic here
}
Related
I am currently using VBScript in Qlikview and I ran into a problem. My code currently looks like this:
sub resize
set obj = ActiveDocument.GetSheetObject("TX05")
set fr = obj.GetFrameDef
set pos = fr.Rect
set WidthUser = ActiveDocument.Variables("vWidth")
' set OriginalWidth = pos.Width
' set OriginalHeight = pos.Height
' Ratio is 2.5
pos.Width = Cint(WidthUser.GetContent.String) * 2.5
' pos.Height = vPreferredWidth/vOriginalWidth * vOriginalHeight
pos.Height = 200 * 2.5
obj.SetFrame fr,true,dummy
msgbox("Changed Width to: " & pos.Width/2.5 & " " & Chr(13) & "Changed Height to: " & pos.Height/2.5)
End sub
vWidth is a variable where the user can input his desired width.
So what am I trying to achieve? I want the user to be able to type in his desired width of an object and then press a button called "resize". When the button is pressed, the object width should change to the desired width and the object height should also change in relation to the change in width.
For example, we start with an object that has a Width of 120 and a height of 200. The user then puts in his desired Width of 60 and then presses the button "resize". The object width should change to 60 and the object height should change to 100 (60/120*200=100). So in the end result the ratio width/height is still the same (120/200 vs 60/100).
The problem I am having is trying to capture the original width and height of my object. I tried using:
set OriginalWidth = pos.Width
set OriginalHeight = pos.Height
But that doesn't work at all. I tried all kinds of variations but nothing worked so far. What I don't understand is that when I type:
msgbox(pos.Width)
I do get a result, but when I use:
set OriginalWidth = pos.Width
msgbox(OriginalWidth)
I get nothing at all (I get thrown back into my script).
Can anyone help me figure this out? Would also love some feedback on the rest of the code, because I just started learning this.
Thanks in advance!
EDIT after help I changed my code to:
sub resize
' Ratio is 2.5
set obj = ActiveDocument.GetSheetObject("TX05")
set fr = obj.GetFrameDef
set pos = fr.Rect
set WidthUser = ActiveDocument.Variables("vWidth")
set HeightUser = ActiveDocument.Variables("vHeight")
OriginalWidth = pos.Width
OriginalHeight = pos.Height
DesiredUserWidth = Cint(WidthUser.GetContent.String)
pos.Width = DesiredUserWidth * 2.5
pos.Height = DesiredUserWidth / OriginalWidth * OriginalHeight * 2.5
obj.SetFrame fr,true,dummy
msgbox("Changed Width to: " & pos.Width/2.5 & " " & Chr(13) & "Changed Height to: " & pos.Height/2.5)
End sub
Read the docs for Set and from now on use it only when you assign an object to a variable.
set OriginalWidth = pos.Width
==>
OriginalWidth = pos.Width
We are putting together a new standard signature using vbs for Outlook.
Everything looks great but design would like the phone numbers to look like the attached image. The "O" for office # in Orange and then the number in blue, the "C" for cell # in Orange and then the number in blue.
I can get the entire cell to be one color, but I don't see how to do 2 colors.
The signature is in a table with the logo in one cell that has 5 rows merged and then the other side has 5 rows.
Here is some of my code:
strName = objUser.FullName
strTitle = objUser.Title
strPhone = objUser.telephoneNumber
strMobile = objUser.mobile
strOffice = "O "
strCell = "C "
objTable.Cell(3,2).Range.Font.Name = "Lato"
objTable.Cell(3,2).Range.Font.Size = "12"
objTable.Cell(3,2).Range.Text = strOffice & strPhone & " " & strCell & strMobile
Start recording a macro do it manually by editing the in the cell or the formula bar. Stop the macro and step into it to get all the colors. I stuck to the main colors on the bottom of the pallet. You'll may have to track ThemeColor, TintAndShade and ThemeFont depending on the colors you choose.
This should get you started
Public Sub AddLogo(r As Range)
Dim i As Integer
Dim ColorArray
ColorArray = Array(-16777024, -16776961, -16727809, -16711681, -11480942, -11489280, -1003520, -4165632, -10477568, -6279056)
r = "Excel Magic"
For i = 0 To UBound(ColorArray)
With r.Characters(Start:=(i + 1), Length:=1).Font
.Color = ColorArray(i)
End With
Next
End Sub
Usage:
AddLogo objTable.Cell(3,2)
A chart on a form I created has two overlapping areas. The overlapping part works just fine. The problem is that visible graph only takes up half the height of the chart control:
The bottom half of the control is left empty (presumably because that's where the second area would have gone were the two areas not aligned?). I can't figure out how to get the chart to use the entire control. The code is below:
chart1.Dock = DockStyle.Fill;
chart1.Legends.Add(new Legend { Name = "Legend1" });
chart1.Location = new Point(435, 3);
chart1.Name = "chart1";
chart1.Size = new Size(426, 287);
chart1.TabIndex = 2;
chart1.Text = "chart1";
var firstArea = chart1.ChartAreas.Add("First Area");
var seriesFirst = chart1.Series.Add("First Series");
seriesFirst.ChartType = SeriesChartType.Line;
seriesFirst.Points.Add(new DataPoint(10, 55));
seriesFirst.Points.Add(new DataPoint(11, 56));
seriesFirst.Points.Add(new DataPoint(12, 59));
var secondArea = chart1.ChartAreas.Add("Second Area");
secondArea.BackColor = Color.Transparent;
secondArea.AlignmentOrientation = AreaAlignmentOrientations.All;
secondArea.AlignmentStyle = AreaAlignmentStyles.All;
secondArea.AlignWithChartArea = firstArea.Name;
secondArea.AxisY.LabelStyle.Enabled = false;
secondArea.AxisX.LabelStyle.Enabled = false;
var seriesSecond = chart1.Series.Add("Second Series");
seriesSecond.ChartType = SeriesChartType.Line;
seriesSecond.ChartArea = secondArea.Name;
seriesSecond.Points.Add(new DataPoint(10, 1001));
seriesSecond.Points.Add(new DataPoint(11, 1015));
seriesSecond.Points.Add(new DataPoint(12, 1016));
This is some old code I've dug out and modified to suit your example. The problem is the InnerPlotPosition.Auto and Position.Auto status of the ChartAreas, thats why after you add the second chart the first charts auto position jumps up and then the second chart aligns with the new InnerPlotPosition.Auto values.
You can try turning this off but I think its easier to just position the first chart manually and then allow the second to align with the new manual position. It produces the below image (minus your legend you can work the values needed yourself)
Bit of pain in the ass solution but hopefully it helps
Dim chart1 As New Chart
Me.Controls.Add(chart1)
chart1.Location = New Point(435, 3)
chart1.Name = "chart1"
chart1.Size = New Size(426, 287)
chart1.TabIndex = 2
chart1.Text = "chart1"
Dim firstArea As ChartArea = chart1.ChartAreas.Add("First Area")
Dim seriesFirst = chart1.Series.Add("First Series")
seriesFirst.ChartType = SeriesChartType.Line
seriesFirst.Points.Add(New DataPoint(10, 55))
seriesFirst.Points.Add(New DataPoint(11, 56))
seriesFirst.Points.Add(New DataPoint(12, 59))
Dim secondArea As ChartArea = chart1.ChartAreas.Add("Second Area")
secondArea.BackColor = Color.Transparent
secondArea.AlignmentOrientation = AreaAlignmentOrientations.All
secondArea.AlignmentStyle = AreaAlignmentStyles.All
secondArea.AlignWithChartArea = firstArea.Name
secondArea.AxisY.LabelStyle.Enabled = False
secondArea.AxisX.LabelStyle.Enabled = False
Dim seriesSecond = chart1.Series.Add("Second Series")
seriesSecond.ChartType = SeriesChartType.Line
seriesSecond.ChartArea = secondArea.Name
seriesSecond.Points.Add(New DataPoint(10, 1001))
seriesSecond.Points.Add(New DataPoint(11, 1015))
seriesSecond.Points.Add(New DataPoint(12, 1016))
' *** Set locational values here for your first chart***
Dim heightAboveChartArea As Integer = 20
Dim heightBelowChartArea As Integer = 20
Dim axisLabelHeight As Integer = 40
Dim widthLeftOfChartArea As Integer = 20
Dim widthRightOfChartArea As Integer = 20
Dim heightPerBar As Integer = 20
Dim numberOfPoints As Integer = chart1.Series(0).Points.Count
' *** The following code should not normally be modified ***
chart1.Height = heightAboveChartArea + heightBelowChartArea + axisLabelHeight + (numberOfPoints * heightPerBar)
chart1.ChartAreas(0).Position.X = widthLeftOfChartArea / chart1.Width * 100
chart1.ChartAreas(0).Position.Width = 100 - (widthRightOfChartArea / chart1.Width * 100) - chart1.ChartAreas(0).Position.X
chart1.ChartAreas(0).Position.Y = (heightAboveChartArea / chart1.Height * 100)
chart1.ChartAreas(0).Position.Height = 100 - (heightBelowChartArea / chart1.Height * 100) - chart1.ChartAreas(0).Position.Y
I thought about monkeying with the position, but I'd have to take into account borders and the legend and other chart components and assumed I'd never get it as good as the auto-positioning provided by the chart - and it would drive me nuts. However, the suggestion by TylerDurden led me to the idea of simply delaying the addition of the second series/area until after the chart had rendered at least once and had calculated the position. This turned out to be non-trivial, since for most of the chart's initialization the X, Y, Height and Width are still zero. The best way I found was to add the second series in the Form's Shown event:
private void OnShown(object sender, EventArgs eventArgs)
{
Application.DoEvents();
var f = chart1.ChartAreas[0].Position.ToRectangleF();
chart1.ChartAreas[0].Position.Auto = false;
chart1.ChartAreas[0].Position.X = f.X;
chart1.ChartAreas[0].Position.Y = f.Y;
chart1.ChartAreas[0].Position.Height = f.Height;
chart1.ChartAreas[0].Position.Width = f.Width;
// add second area/series here
The call to Application.DoEvents() is required to force the chart to render and calculate the Position. Since Position is a percentage, both chart areas will always occupy the full height and width of the parent Chart.
I am working on a Dashing project using Sinatra, and I am displaying Graphs on the dashboard. I've been having a lot of trouble with displaying Timestamps on the X-Axis, Now that I have this working, I have another problem. On my graph, the x-axis keeps repeating the timestamp over and over again. What I mean by this is that it does not show any of the previous timestamps it just repeats the current timestamp over and over again, this is not what I want. Below is my code for the graph:
class Dashing.Graph extends Dashing.Widget
#accessor 'points', Dashing.AnimatedValue
#accessor 'current', ->
return #get('displayedValue') if #get('displayedValue')
points = #get('points')
if points
points[points.length - 1].y
#ready is triggered when ever the page is loaded.
ready: ->
container = $(#node).parent()
# Gross hacks. Let's fix this.
width = (Dashing.widget_base_dimensions[0] * container.data("sizex")) + Dashing.widget_margins[0] * 2 * (container.data("sizex") - 1)
height = (Dashing.widget_base_dimensions[1] * container.data("sizey"))
#graph = new Rickshaw.Graph(
element: #node
width: width
height: height
renderer: #get("graphtype")
series: [
{
color: "#fff",
data: [{x:0, y:0}]
}
]
)
#graph.series[0].data = #get('points') if #get('points')
format = (d) ->
months = new Array(12)
months[0] = "Jan"
months[1] = "Feb"
months[2] = "Mar"
months[3] = "Apr"
months[4] = "May"
months[5] = "Jun"
months[6] = "Jul"
months[7] = "Aug"
months[8] = "Sep"
months[9] = "Oct"
months[10] = "Nov"
months[11] = "Dec"
today = new Date()
month = today.getMonth()
day = today.getDate()
h = today.getHours()
m = today.getMinutes()
if(m <= 9)
d = months[month] + " " + day + " " + h + ":" + 0 + m
else
d = months[month] + " " + day + " " + h + ":" + m
x_axis = new Rickshaw.Graph.Axis.X(graph: #graph,pixelsPerTick: 100, tickFormat: format )
y_axis = new Rickshaw.Graph.Axis.Y(graph: #graph, tickFormat: Rickshaw.Fixtures.Number.formatKMBT)
#graph.render()
#onData is responsible for handling data sent from the jobs folder,
#any send_event methods will trigger this function
onData: (data) ->
if #graph
#graph.series[0].data = data.points
#graph.render()
node = $(#node)
value = parseInt data.points[data.points.length - 1].y
cool = parseInt node.data "cool"
warm = parseInt node.data "warm"
level = switch
when value <= cool then 0
when value >= warm then 4
else
bucketSize = (warm - cool) / 3 # Total # of colours in middle
Math.ceil (value - cool) / bucketSize
backgroundClass = "hotness#{level}"
lastClass = #get "lastClass"
node.toggleClass "#{lastClass} #{backgroundClass}"
#set "lastClass", backgroundClass
Can anyone help me understand why my graph does not want to show any previous values of X?
I think your issue is the call to today = new Date() in function format. The formatter is getting a date passed in by Rickshaw/D3, the date just needs to be formatted according to your needs. By calling today = new Date(), you are ignoring the passed in date and instead providing your own/new date.
Side note: you can take a look at D3's date/time formatting or moment.js for simpler date/time formatting, so your format function could shrink to 1 or 2 lines of code.
Dim cont = 0
If ListBox1.Items.Count > 0 Then
For i =1 To ListBox1.Items.Count
Dim botao3 As New Button
botao3.Text = CStr(ListBox2.Items(cont)) 'table.Item(i).text &
botao3.BringToFront()
botao3.Top = top
botao3.Left = 40
botao3.Width = 300
Me.Controls.Add(botao3)
top = top + 30
cont = cont + 1
Next
End If
ps. my listbox has the sorted propriety set to true
this its my code but it will only give it the name of the last inserted value on the listbox .
how can i make this so that when ever i click the button it deletes the old set of buttons and add a new set of button the one i have just inserted.
and please give me a hand :$
You put 0 instead of the current loop value
botao3.Text = CStr(ListBox2.Items(0))
should be
botao3.Text = CStr(ListBox2.Items(i))
For the other part, I am not sure what you want to achieve but you can have Me.Controls.Clear() before your loop.
try that:
If ListBox1.Items.Count > 0 Then
For i =0 To ListBox1.Items.Count
Dim botao3 As New Button
botao3.Text = CStr(ListBox1.Items(i)) 'table.Item(i).text &
botao3.BringToFront()
botao3.Top = top
botao3.Left = 40
botao3.Width = 300
Me.Controls.Add(botao3)
top = top + 30
Next
End If
use this:
Dim btn As Button() = New Button(ListBox1.Items.Count - 1) {}
For i As Integer = 0 To ListBox1.Items.Count - 1
btn(i) = New Button()
btn(i).Text = ListBox1.Items(i).ToString()
If i > 0 Then
btn(i).Left = btn(i - 1).Right
End If
Me.Controls.Add(btn(i))
Next
result: