Rendering a chart over several days, with a dataset that has 24 hour data, but it's only useful during M-F, 7AM to 5PM. If I setup a time series with the code below, I get a chart that contains all 24 hours, 7 days a week. Makes sense, but not for my use case.
Is there a way to define what interval the time series displays? Or do I need to use a different chart type and attempt to fit my data into regular periods? I hope not the latter, while the data I receive is usually in 30 second intervals, there can easily be gaps.
It's pretty impossible to post an SSCE of a working UI with a chart dynamically asking for data from a server, but some highlights are below to get an idea of the chart types I'm using.
Some of the plot.add, CombinedDomainXY, index 0 code may seem strange. I have three subplots with the shared time values, I've pared it down to one here to keep it short. I assume there is a way to do what I need for one plot it would work for a chart with multiple subplots.
public ChartPanel extends JPanel
{
private final MyDataset _myDataset = new MyDataset();
private final XYPlot _myPlot = new XYPlot();
_chartPanel = new ChartPanel( createChart() );
private JFreeChart createChart()
{
CombinedDomainXYPlot plot = new CombinedDomainXYPlot(
timeAxis );
plot.setGap( 10.0 );
plot.setDomainPannable( true );
plot.setDataset( index, dataset );
NumberAxis axis = new NumberAxis();
axis.setAutoRangeIncludesZero( false );
plot.setRangeAxis( 0, axis );
plot.setRangeAxisLocation( 0, axisLocation );
plot.setRenderer( 0, new StandardXYItemRenderer() );
plot.mapDatasetToRangeAxis( 0, index );
// add the subplots...
plot.add( _myPlot, 1 );
}
}
public class MyDataset implements XYDataset
{
@Override
public double getYValue( int series, int item )
{
return getMyData(item);
}
@Override
public double getXValue( int series, int item )
{
return _bars.get( item ).DateTime.toInstant().toEpochMilli();
}
//other basic overloaded methods left out for brevity
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…