Chart mutiple scaling and generating of misssing data (store point if value changed)
-
Hi,
JFreeChart supports multiple scaling groups, it would be handy to draw values that lie in a different range onto the same chart with different scalings.
For instance if you have a binary value and temperatures at 70 °C and a outside temp at 6 °C. Currently its hard to find the correlation of the values.If I draw a chart where one value is stable and the value is stable after the chart time ends, it will only be drawn to the last changed point in the time range of the chart. Maybe provide "virtual" values at the begin? and end if the time range.
I encounter some funny charts where a value chages drastically in a short term (it jumps) and was before for a long time very stabel. Instead of a steep acend I get a slow.
Solution: If a value changes store not only the actual changed value but store as well the last value of the stable sequence.Arne
-
JFreeChart supports multiple scaling groups, it would be handy to draw values that lie in a different range onto the same chart with different scalings.
Some sample code would go a long way to getting this included in Mango.
I encounter some funny charts where a value chages drastically in a short term (it jumps) and was before for a long time very stabel. Instead of a steep acend I get a slow.
That is a very typical way of representing the data in a chart.
Solution: If a value changes store not only the actual changed value but store as well the last value of the stable sequence.
"if/then" logging code like this complicates the matter quickly, and often has disconcerting unintended consequences. Overall, I'd be very hesitant to start logging data values that were not actually received from the data source.
-
@apl said:
JFreeChart supports multiple scaling groups, it would be handy to draw values that lie in a different range onto the same chart with different scalings.
It would sometimes be nice to have primary and secondary Y-axis on charts. A simple checkbox beside the point when added to reports would suffice to indicate if it should be plotted on lefthand or righthand Y axis.
I encounter some funny charts where a value chages drastically in a short term (it jumps) and was before for a long time very stabel. Instead of a steep acend I get a slow.
This sounds like having points logged "On change", if they were logged on interval your jump would only be as big as the largest change during a single interval.
I mostly use "interval" logging and would like to one day make it so missing intervals are plotted as null values so the line is not continuous. I've done that before with JFreeChart.
[quote]
Solution: If a value changes store not only the actual changed value but store as well the last value of the stable sequence."if/then" logging code like this complicates the matter quickly, and often has disconcerting unintended consequences. Overall, I'd be very hesitant to start logging data values that were not actually received from the data source.[/quote]
As a worst case you could log the preceeding point value for every point value that is logged, if the preceeding point value wasn't logged already. You would end up with twice as many point values logged, but would have no "jumps" on the plot larger than the "on change" tolerance.
-
Here is code lifted fom an other program - hope this helps
private void createChart() { JFreeChart chart = null; XYPlot plot = null; XYItemRenderer renderer = null; map.clear(); try { chart = ChartFactory.createTimeSeriesChart(model.getCaption(), null, null, null, true, true, false); chart.setBackgroundPaint(Color.WHITE); chart.addSubtitle(new TextTitle(Messages.getString("DiagramViewPanel.MSG.Diagram_Subtitle"))); plot = chart.getXYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(Color.WHITE); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.getRangeAxis().setFixedDimension(15.0); DateAxis domainAxis = (DateAxis) plot.getDomainAxis(); domainAxis.setDateFormatOverride(new SimpleDateFormat( "dd.MM.yyyyy HH:mm:ss")); renderer = plot.getRenderer(); if ((model.getScalingGroupCount() != 0) && (model.getScalingGroup(0).getScalingDataPointCount() != 0)) { renderer.setPaint(model.getScalingGroup(0).getScalingDataPoint( 0).getColor()); } } finally { diagramView.setChart(chart); } int groupIndex = 0; int dataPointIndex = 0; for (ScalingGroup scalingGroup : model.getScalingGroupsIterable()) { NumberAxis axis = new NumberAxis( String.format( "%s [%s]", new Object[]{scalingGroup.getCaption(), scalingGroup.getUnitOfMeasurement()})); axis.setFixedDimension(10.0); axis.setAutoRangeIncludesZero(false); axis.setLabelPaint(scalingGroup.getColor()); axis.setTickLabelPaint(scalingGroup.getColor()); plot.setRangeAxis(groupIndex, axis); plot.setRangeAxisLocation(groupIndex, AxisLocation.BOTTOM_OR_LEFT); for (ScalingDataPoint scalingDataPoint : scalingGroup.getScalingDataPointsIterable()) { try { TimeSeriesCollection dataset = new TimeSeriesCollection(); TimeSeries series = new TimeSeries(scalingDataPoint.getCaption(), Millisecond.class); map.put(scalingDataPoint, series); dataset.addSeries(series); plot.setDataset(dataPointIndex, dataset); plot.mapDatasetToRangeAxis(dataPointIndex, groupIndex); renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, scalingDataPoint.getColor()); renderer.setSeriesStroke(0, new BasicStroke(scalingDataPoint.getLineWidth(), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, scalingDataPoint.getLineShapeAsArray(), 0.0f)); plot.setRenderer(dataPointIndex, renderer); log.debug(dataPointIndex + " scalingDataPoint added: " + scalingDataPoint.getCaption()); } catch (Exception ex) { log.error("Error during data retrieving.", ex); } dataPointIndex++; } log.debug(groupIndex + " scalingGroup added: " + scalingGroup.getCaption()); groupIndex++; } return; }
Arne
-
@m,
thanks for the scaling in charts (nango 1.8.2)!
Topic save last old value:
If one has datapoints that really jump (i.e. between 0 and 1) it would be nice to have the values jump in the chart as well.
See attached patch.
One could improve this patch by tracking how many old values where discarted and have a threshold after which the last old value gets stored.
IE if 10 old values are discarted ant the value changes, then the last old value and the current value gets stored in the database.I dont know if this complicates matters to much maybe add just a CheckBox for yes/no at the moment and internally set the value to 0 or 1 ... ?
Arne
Attachment: download link
-
Hi Arne,
If this is really to address an issue with charting, then perhaps a code fix should be done in the charts. The problem is that the patch will start saving a bunch of points and using up space unnecessary as far as every other function in Mango is concerned.
I think i might be better to use a step-type plot in a chart for points with this kind of behaviour rather than a line chart. Alternatively, you can just have Mango log all data instead of on change.
-
Do you code the step-chart, or should I do it?
Arne