Category axis - ticks formatting - dimple.js

I have a case where data presented on the chart is gathered in five minutes interval during the working hours, while at night it stays idle. When the chart presents data from a couple of days, there are obviously a flat lines between days (during nights).
Using category axis solves the problem with long steady lines during nights. However using time axis I was able to format date and use time interval property.
How can I do that using category axis? I mean formatting tick labels and achieve similar behaviour to using time intervals?
That is how it looks like at the moment using category axis:
I would like to present just one tick for every day, properly formatted.
Thank you in advance for any help.

You can do this by using a grouped category axis, It will involve a little manipulation of your dates into a separate time part and day part using some code like this:
// Create a d3 parser for this particular date format, this may not be relevant
// if you already have actual dates
var inFormat = d3.time.format("%Y-%m-%d %H:%M");
// Create a d3 parser for the day and time formats we are going to use
var dayFormat = d3.time.format("%d %b"),
timeFormat = d3.time.format("%H:%M");
// Add some code to manipulate the date into 2 separate fields
// because this is a category axis you need to handle formatting here
// category axes use text content
data.forEach(function (d) {
// Convert the date to an actual date, you may not need to do this if
// you already have date objects in your data
var inDate = inFormat.parse(d.Date);
// Add a new field for the time portion
d["Day"] = dayFormat(inDate);
d["Time"] = timeFormat(inDate);
}, this);
Here it is in context doing what I think you want:
http://jsfiddle.net/87GHM/1/

Related

Chartist Different Series

I'm using Chartist to create charts.
i have day labels:
1,2,3,4,5 and so on
I have a serie like this:
1131586,1132542,1133480,1134294,1135146,1136253,1137259,1139946 and so on
No i add a new line with different series of value. The new line show the difference between a point and another like this:
0,956,938,814,852,1107,1006,2687,1859,879,900,765 and so on
The chart show two horizantal lines!
How can i show the lines correctly?
In general if you have 2 data series and a label you would do something like this:
new Chartist.Line('#chart4', {
labels: [1,2,3,4,5],
series: [[1131586,1132542,1133480,1134294,1135146,1136253,1137259,1139946],[0,956,938,814,852,1107,1006,2687]]
});
With the following result (Top Chart):
http://codepen.io/k3no/pen/ozrgNq
Chartist is working correctly, it is your data that needs to be different, or in other words, it needs to be normalized so it can be displayed in the same chart.
You have a few options:
Display 2 charts one on top of the other (middle 2 charts), notice at this point you can already draw your conclusions and the data has not been tampered with, so this is my preferred method whenever possible and data permitting.
Normalize one data series to the other, or both (it's a bit of a complex issue and outside of scope, but here's an introduction):normalization
Preprocess your data so you display a single line.

How to display comparisons with set expression?

My dataset has WeekEndingDate and Sales. I am displaying a straight table with all the selected data but I need to have another table showing the following:
Sales (other columns...)
First week : 1,000
Last week : 1,350
Difference : 350
Difference %: 35%
My questions:
a) Can I have the above in one chart/table, or I need 4 different charts showing columns filtered by set expressions?
b) My strategy is having 2 variables (vMinWeek and vMaxWeek), and using them in set expressions. Is that the best route?
c) My set expressions (below) are not working - they sum the whole data set. Would you please help me understanding why?
=max ({$<WeekEndingDate={'$(vMinWeek)'}>} Sales)
Thank you for your help!
Mara
I think the reason your set isn't working is that your WeekEnd date is formatted as a date and your variable is formatted as a number.
The trick with Set Analysis is always to think what you would have to type in a list box to get to your answer. So even though QlikView stores WeekEnd 2014/08/18 as 41869 you can't type 41869 in the WeekEnd list box and get back that date. So I would make your variables of the form =date(min(WeekEnd)).
The second part of your question; getting the table you want. I would do like this. I make a loose table with the dimension values, dual is so that it sorts correctly in the chart we are going to build.
load dual(D,N) as DIM inline [
D,N
First Week,1
Last Week,2
Difference,3
Dif %,4
];
I like defining my variables in the script as well, so I would do this.
set vFirstWeek='=date(min(WeekEnd))';
set vLastWeek='=date(max(WeekEnd))';`
Then when building the straight table we use the dimension as DIM but because DIM isn't connected to anything we have to do some work to get it to display values that fit those dimension values. The num(,'# ##0') is just to format the % differently from the sums. For this to work the number format in the Number tab of the chart must be set to Expression Default.
if(DIM='First Week',num(sum({<WeekEnd={'$(vFirstWeek)'}>} Sales),'# ##0'),
if(DIM='Last Week',num(sum({<WeekEnd={'$(vLastWeek)'}>} Sales),'# ##0'),
if(DIM='Difference',num(sum({<WeekEnd={'$(vFirstWeek)'}>} Sales)-sum({<WeekEnd={'$(vLastWeek)'}>} Sales),'# ##0'),
if(DIM='Dif %',num((sum({<WeekEnd={'$(vFirstWeek)'}>} Sales)-sum({<WeekEnd={'$(vLastWeek)'}>} Sales))/sum({<WeekEnd={'$(vLastWeek)'}>} Sales),'0.00%')))))

Auto incrementing w/ a vb.net chart control

I'm curious to know if the DataVisualization.charting.chart in vb.net does any auto counting / plotting for my particular issue.
I have a file with thousands of User Agent Strings which were generated over a period of time. The UA Strings are generated from user logins.
In my program, I am identifying approximately 45 different environments as: Operating Systems + Browser Type (ie., "Windows 7 + IE10"). Each login also has a date stamp in the format of YYYY-MM.
My task is to do a line chart where I have Environment (Y-axis) vs Date (X-axis) using the vb.net charting control. I would like the control to increment each time I have a particular data set rather than keeping a hideous amount of arrays & counter data for my chart.
Does the vb.net charting control auto increment in this way? I am not able to find anything so far.
I'm not sure I understand the question (what is it that you want to auto increment? The axis min/max? The date? Something else?), but if you want the axes to update each time you add a new point, the chart certainly supports that. Just call Chart.ResetAutoValues() after you add the new point(s), and it will figure out new ranges for both axes.
Edit: Arrange your data before adding it to the chart. Something like:
Dictionary<string, int> values = new ...;
string[] uaStrings = ReadFileOfUAStrings();
foreach (string uaString in uaStrings)
{
values[uaString]++;
}
foreach (KVP in values)
{
chart.Series(kvp.Key).Points.Add(kvp.Value);
}
The above doesn't separate things out by date, but you should get the idea. As written, it's also not very efficient if another UA string is added to the file and the whole thing is re-read, but optimizations can come after it's functional.

TimeSpan not calculating

I am trying to calculate create a time remaining calculator in VB.NET and it won't let me and I can't seem to figure out why. Here is my code
Dim PrefendinedDateTime As DateTime = "3:00:00"
Dim TimeNow As DateTime = DateTime.Now
Dim ElapsedTime As TimeSpan = (TimeNow - frmStartDateTime)
Dim TimeRemaining As TimeSpan = PrefendinedDateTime - New DateTime(ElapsedTime.Ticks)
txtTimeRemaining.Text = New DateTime(TimeRemaining.Ticks).ToString("HH:mm:ss")
I get this error message:
Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.
Parameter name: ticks
Not quite sure what this means
You cannot cast a timespan to a date, because those are different ticks. What you need is this:
txtTimeRemaining.Text = TimeRemaining.ToString("g")
or this:
txtTimeRemaining.Text = TimeRemaining.ToString("hh\:mm\:ss")
Notice how format string is different for TimeSpan, compared to formatting a date time, for example, and that : now requires escaping. This is explained in detail in below link #2.
References:
Standard TimeSpan Format Strings # MSDN
Custom TimeSpan Format Strings # MSDN
Let's stop here for a second, while I try to explain why it did not work for you. Forget about ticks, think in seconds, because it's a measurable interval, that's easy to get a grasp on. Suppose you time interval is a second. Now you are trying to create a date, passing one second into it. What do you expect to get? 1 second AD, i.e. 1st year, 1st month etc.? Fair enough.
Suppose now you have an interval of minus 1 second (yes, intervals can be negative). You would think it's 1 second BC, right? Unfortunately, negative dates in .NET are not allowed.
As a general rule of thumb, intervals of time (represented in .NET by a TimeSpan), and points in time (represented by a DateTime) should be treated separately, because they are logically different entities. There is one-way relation though, i.e. two dates can represent a TimeSpan. However, a TimeSpan does not represent two dates. In fact, no matter how many TimeSpans you have, you will never be able to relate them to any point in time.

Need to set time range on Y axis on a MSChart

I'm looking to set the y-axis for a MSChart to be midnight to midnight, in either regular time format(i.e. - "1:30 AM") or military time. I figured out I can specify the y-axis format using ChartArea.AxisY.LabelStyle = new LabelStyle() { Format = "HH:mm" }, but cannot figure out what to set the minimum/maximum values to be.
Has anyone employed this format?
There are a few things you need to do to get this working properly.
MSChart accepts DateTime objects as Y values. You can emulate durations by doing this for each of your data points (assuming they are timespans or something convertible into a TimeSpan):
TimeSpan testSpan = TimeSpan.FromMinutes(5);
YourChart.Series(0).Points.AddY(new DateTime(testSpan.Ticks))
That will convert it into a datetime starting from the the beginning of CLR time (e.g. 1/1/0001 12:05:00 AM).
Then just use the label format "HH:mm" on the Y-axis.
<asp:ChartArea Name="VsChartArea">
<AxisY Minimum="0">
<LabelStyle Format="HH:mm" />
</AxisY>
</asp:ChartArea>
That should make it look like this:
To setup a custom interval (5 minutes):
<AxisY Minimum="0" IntervalType="Minutes" Interval="5">
Hope this helps!
I found a workaround since I never could get the formatting to work natively with DateTime values.
I eventually changed my Y axis data to be in integer format, with ranges from 0 to 2400(2359 really) to represent military time. I then updated the LabelStyle.Format to be "00:00" which renders my integer values into military time.
Yay for me. Hope this helps someone else.
If you use the Military time, do you notice that your scale is nolonger linear?