I have the codes on jsfiddle
http://jsfiddle.net/9qdBD/
I am able to plot out the axises and grid line, but when it comes to the actual line, I got parsing issue. Not sure why. I am probably missing something obvious. Here is the error I got.
Error: Problem parsing d="MNaN,1LNaN,8LNaN,2LNaN,10LNaN,3LNaN,20LNaN,90"
Here the updated, working jsFiddle
A couple of things were wrong:
For the x coordinates of the line you had
formatter(parser.parse(d.date))
First, calling formatter on the parsed date produces a String, which is not what you want for plotting values. You need quantitative values of date, so just parser.parse(d.date)
Next, you need to to convert each date to an x-position along the x-axis. You had created an x-scale (assigned to the var x in your code), which you're using to draw the axis, and you need to use that same scale to convert the dates to the said x-positions:
return x(parser.parse(d.date))
That fixes the x positions. Then you need to do a similar thing for converting your y values to y positions:
return y(d.total)
Related
I want to use the Highcharts StockChart library to make a chart. Here's more info on the chart I need to create:
The type of the chart is datetime
The data is being updated on every minute (it's data from stocks), so the chart is being constantly updated.
The data of the chart is from 9:00am to 11:40am and then from 12:35pm to 3:00pm (there's a lunch break).
The data is being shown with bars in an interval of 5 minutes (data is received for every 5 minutes except for the lunch break).
The bars will start to be drawn from left to right as the data is received.
The bars width needs to be the same size regardless of how many data is being shown on the chart.
The labels of x axis of the chart need to be always the same and on the same position (from 9:00am to 3:00pm every hour) even when there's missing data (a line must be drawn on the x axis).
So, I'm using the max property set to that day at 3:00pm on the x axis of the chart. With this, I can:
Have the bars width to be the same
Have the x axis be drawn regardless of the missing data on the same interval (until 3pm).
Everything works ok until the lunch break (11:40am). However, when receiving data for 12:35pm (after lunch break), the chart will ignore the max property and the last line of the x axis that is drawn is until 1pm (this line needs to be drawn until 3pm). I assume that this is because until 11:40am all the data for 5 minutes is present, so the chart understands the interval on which the data needs to be drawn and also can draw the x axis lines on the same interval. But as soon as there's a gap on the data, the chart doesn't know anymore if data will keep coming in an interval of 5 minutes, so will just take into consideration all the data that has received until now, ignoring the max property.
I have tried different options in order to solve the issue:
I used ordinal property set to false. With this, I can solve the issue of the missing x axis labels until 3pm, but the issue is that the lunch break will have a gap on the chart. I need to merge the lunch break and having the x axis labels drawn until 3pm.
I tried to use the tickInterval property and was able to set the interval of the x axis but only for the data that is being drawn. However, the x axis label it still until 1pm and needs to be until 3pm.
I tried to use the breaks property for the lunch break while using the ordinal property set to false but didn't work. Also, the chart needs to be merged on the lunch break; using this property will create a gap on purpose, so this property won't help me to fix this issue.
So, I noticed that the interval is being changed correctly where there's data, but the lines are not being drawn where there's no data on the x axis (only until 1pm and not until 3pm). And if I use the ordinal property, it will show all the x axis lines for the missing data, but need to hide the gap for the lunch break.
Any help with this is appreciated =)
UPDATE:
I noticed that when there's still no data, if using v1.3.1 of highcharts (the one I'm currently using), the x axis lines are being drawn correctly until 3pm, but if using the latest version this doesn't happen. It seems that the max property is being ignored for the latest version.
Including the links of jsfiddle for my code on the comments (since stackoverflow doesn't allow me to post many links because don't have enough reputation).
I was able to achieve what I wanted. In the end what I did was to create null data to fill this gap for the lunch break. Also, I created null data for the remaining data until 3pm, that way the x axis lines were drawn properly: https://jsfiddle.net/K4Cj6/201/:
[1504528800000,null,null,null,null]
Thanks anyway guys =)
While I'm dynamically building a chart, I need to add some SVG elements in it. To do so, I convert some coordinates into pixels coordinates via ToPixels.
However if I call ToPixels on my axes before it is being rendered, the value I'm getting is invalid. It should be around 800 and I'm getting values around 33000.
I have a workaround which is to call redraw before I call ToPixels but I don't think I should have to do that.
I'm using the built-in spline curve fit to an x-y plot. Is there a way of getting access to the splined data that HighCharts itself is plotting? I (obviously) have access to my supplied x,y co-ordinates but I'd like access to the HighCharts-calculated spline intermediate values.
Take http://www.highcharts.com/demo/spline-symbols as an example. The raw data is (month,temperature) and the closest point to the mouse get displayed as a tooltip. I'm interested in displaying the intermediate 'points' so that as I move my mouse along a line it displays the calculated spline values.
Is this possible?
This has been dormant for a while but I did manage to figure out a way of doing it. See also a related follow up question.
Say you want to find a 'y' value for a given 'x' on a HighCharts generated spline. If you can get at the SVG path for that spline then you can walk it's length until you hit the required 'x'. Then read off the required 'y'.
This fiddle gives an example: https://jsfiddle.net/r3f2xL6b/1/
So I have an x axis of type datetime, and a series of type column:
http://jsfiddle.net/drmrbrewer/215tnLna/3/
Now, in reality, the spacing of points on the x axis may not always be uniform as in the above example. For example, let's drop a couple of the points to create a non-uniform spacing:
http://jsfiddle.net/drmrbrewer/215tnLna/4/
What I'd like to happen is for each column to fill the entire span from the relevant point to the previous point, so that the gaps would be entirely filled in the above example.
Is that possible? Hopefully without some horrible hack? From a quick search it seems that there is a suggestion that different series may be required (one for each column width). I'm hoping that isn't the case because (a) it's complicated; and (b) I don't know in advance what spacings I'm going to encounter in the data, so it's even more complicated!
Thanks!
What you are trying to make is a histogram, not a bar chart (even bar/column widths). Perhaps you need to use the histogram chart type? https://www.highcharts.com/docs/chart-and-series-types/histogram-series
I want to use core-plot for drawing line graph dynamically. data won't come at a time, we will be receiving point by point dynamically.
Is it possible to draw the chart dynamically using core-plot i.e drawing point by point as on when we receive the (x,y) point?
Please help me, Thanks.
Yes, you can do this reasonably easily. For each received data point, append it to an array of values to display. As these data points come in, call -reloadData on the Core Plot graph (or just the particular plot) to redraw the graph, passing in the array you just added a value to in response to the -numbersForPlot:field:recordIndexRange: delegate method.
If you need to adjust the plot range to track your data points (for a moving ticker), recalculate the new CPPlotRange for the X axis and set the plot space's xRange property to that.
Use the CPTestApp-iPhone, AAPLot, or StockPlot examples as templates for how to set up the line chart overall, and modify from that starting point.
I do something similar to this on the Mac in a scientific application:
(source: sunsetlakesoftware.com)
Sounds like you could make use of a demo project I put together and wrote about here (not core plot related though).
It draws a EKG graph but should easily be modified to use another input than the repeated "heart beat"...See line 320 in EAGLView.m where the indata is entered into the array.