I have a figure with 2 sets of graphs (detections and localizations). First set (localizations) is red ,orange,pink and second set (detections) is blue,black,cyan. I have created a renderer for each set in order to set the colors. I have set the tooltip to true but when I mouseover on the second set (detection) I can't see the labels. I can see labels only for first set on mouseover(see picture) but not for the other set. Here is my code:
JFreeChart avg_chart = ChartFactory.createTimeSeriesChart(
"Average detections and localizations" ,
"" ,
"" ,
null ,
true , true , false);
avg_chart.setBackgroundPaint(Color.WHITE);
final XYPlot plot = avg_chart.getXYPlot( );
plot.setDataset(0,this.dataset_local);
plot.setDataset(1,this.dataset_detect);
plot.setRangeAxis(0,new NumberAxis("Localizations"));
plot.setRangeAxis(1,new NumberAxis("Detections"));
plot.mapDatasetToRangeAxis(0, 0);
plot.mapDatasetToRangeAxis(1, 1);
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
XYLineAndShapeRenderer renderer1 = (XYLineAndShapeRenderer) plot.getRenderer(0);//localization
renderer1.setSeriesPaint( 0 , Color.RED );
renderer1.setSeriesPaint( 1 , Color.MAGENTA );
renderer1.setSeriesPaint( 2 , Color.orange );
renderer1.setBaseItemLabelsVisible(true);
XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false); //detection ****************
renderer2.setSeriesPaint( 0 , Color.BLUE);
renderer2.setSeriesPaint( 1 , Color.BLACK );
renderer2.setSeriesPaint( 2 , Color.CYAN );
renderer2.setBaseItemLabelsVisible(true);
plot.setRenderer(0,renderer1);
plot.setRenderer(1,renderer2);
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("dd/MM/yyyy"));
return avg_chart;
}
I have tried XYLineAndShapeRenderer renderer2 = (XYLineAndShapeRenderer) plot.getRenderer(1) but it gives be a nulll exception.
ChartFactory.createTimeSeriesChart() adds an XYToolTipGenerator to renderer1 for you when tooltips is true. You probably just need to use it with renderer2:
renderer2.setBaseToolTipGenerator(renderer1.getBaseToolTipGenerator());
Or you can add a new one to renderer2:
XYToolTipGenerator toolTipGenerator2 = StandardXYToolTipGenerator.getTimeSeriesInstance();
renderer2.setBaseToolTipGenerator(toolTipGenerator2);
Related
I am using the following AFL code for "Initial Balance with Range Extension" in AmiBroker -
_SECTION_BEGIN("Initial Balance with Range Extensions");
P11 = Param("IB Start Time",091500, 0 , 235959, 1 ) ;
P12 = Param("IB END Time",101500, 0 , 235959, 1 ) ;
START = (TimeNum()>= P11);
END = (TimeNum()<= P12);
ZONE = START AND END;
ST = (TimeNum()>= P12);
NewTime = ZONE!= Ref(ZONE, -1);
highestoftheday = HighestSince(NewTime,H,1);
Lowestoftheday = LowestSince(NewTime,L,1);
IBHigh = ValueWhen(ZONE,highestoftheday,1);
IBLow = ValueWhen(ZONE,lowestoftheday,1);
ORBClose = ValueWhen(zone,C,1);
IBrange = IBHigh - IBLow; // First Hour Range
IBM = IBLow+IBrange/2;
IB1xh = IBHigh+IBrange ; // Target 1 for range extension upside
IB2xh = IBHigh+2*IBrange ;
IB3xh = IBHigh+3*IBrange ;
IB1xl = IBLow-IBrange ;
IB2xl = IBLow-2*IBrange ; // target 1 for range extension downside
IB3xl = IBLow-3*IBrange ;
PlotGrid(LastValue(IBHigh, True), colorPlum, pattern=10, width = 2, label = True);
PlotGrid(LastValue(IBLow, True), colorPlum, pattern=10, width = 2, label = True);
PlotGrid(LastValue(IBM, True), colorBrown, pattern=10, width = 2, label = True);
PlotGrid(LastValue(IB1xh, True), colorGreen, pattern=10, width = 2, label = True);
PlotGrid(LastValue(IB2xh, True), colorGreen, pattern=10, width = 2, label = True);
PlotGrid(LastValue(IB3xh, True), colorGreen, pattern=10, width = 2, label = True);
PlotGrid(LastValue(IB1xl, True), colorRed, pattern=10, width = 2, label = True);
PlotGrid(LastValue(IB2xl, True), colorRed, pattern=10, width = 2, label = True);
PlotGrid(LastValue(IB3xl, True), colorRed, pattern=10, width = 2, label = True);
_SECTION_END();
This code is plotting continuous horizontal lines. But I need disjointed horizontal lines for individual sessions. How can I get that? Please help me to fix this issue. Thanks for your time and effort. Regards.
I have two problems:
1) First, I want to add a map in AutoCompleteTextField exactlly in DefaultListModel and after I want to add the the listmodel in my autocompletetextField
2) How can I get the text when I select an element in the AutoCompleteTextField?
Form hi = new Form("Auto Complete", new BoxLayout(BoxLayout.Y_AXIS));
AutoCompleteTextField ac = new AutoCompleteTextField("Short", "Shock", "Sholder", "Shrek0", "3asna", "niazra");
ac.setMinimumElementsShownInPopup(5);
//final DefaultListModel<Map<String,Object>> options = new DefaultListModel<>();
final DefaultListModel<String> options = new DefaultListModel<>();
AutoCompleteTextField an = new AutoCompleteTextField(options);
hi.add(an);
ac.addListListener(a -> {
List<Object> ls = new List<>();
System.out.println("i want to display the text selected");
});
hi.add(ac);
hi.show();
When you select an item in the suggestion box of an AutoCompleteTextField the text of this item is copied to the TextField part of the AutoCompleteTextfield, but this occur only after the ListEvent.
In order to have this behavior, prefer using a Selection Listener on the DefaultListModel:
Form hi = new Form("ACTF", new BoxLayout(BoxLayout.Y_AXIS));
DefaultListModel<String> defList = new DefaultListModel<>("Red", "Green", "Blue", "Orange");
AutoCompleteTextField tf1 = new AutoCompleteTextField(defList);
defList.addSelectionListener((oldid, newid)-> Log.p(defList.getItemAt(newid)));
hi.add(tf1);
hi.show();
I don't know why, it occur two times after showing the form, but it works perfectly fine after.
Edit: If you want to display the text on screen, you must use something like this :
Form hi = new Form("ACTF", new BoxLayout(BoxLayout.Y_AXIS));
Label text = new Label("Selected text");
DefaultListModel<String> defList = new DefaultListModel<>("Red", "Green", "Blue", "Orange");
AutoCompleteTextField tf1 = new AutoCompleteTextField(defList);
defList.addSelectionListener((oldid, newid)-> {
text.setText(defList.getItemAt(newid));
hi.revalidate();
});
hi.add(text);
hi.add(tf1);
hi.show();
EDIT 2: Example with a linked map:
Form hi = new Form("ACTF", new BoxLayout(BoxLayout.Y_AXIS));
Map testMap = new HashMap<String, String>();
testMap.put("Red", "Roses are red");
testMap.put("Green", "Grass is green");
testMap.put("Blue", "Sky is blue");
testMap.put("Orange", "Apricots are orange");
Label text = new Label("Selected text");
DefaultListModel<String> defList = new DefaultListModel<>(testMap.keySet());
AutoCompleteTextField tf1 = new AutoCompleteTextField(defList);
defList.addSelectionListener((oldid, newid)-> {
text.setText((String) testMap.get(defList.getItemAt(newid)));
hi.revalidate();
});
hi.add(text);
hi.add(tf1);
hi.show();
My shiny dashboard has checkboxInput and I am trying to align it to right within the title of the box item. For smaller boxes (width of 6) the alignment is proper, however for boxes with width of 12, which ever way I realign the column values, the checkbox input remains at the middle of the box. The code is as follows:
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
skin = "green",
dashboardHeader(
title = "TEST", titleWidth = 225
),
dashboardSidebar(
menuItem("TRENDS", tabName = "vactr", icon = shiny::icon("line-chart"))
),
dashboardBody(
tabItems(
tabItem(
tabName = "vactr",
fluidRow(
box(
width = 12, status = "info", title =
fluidRow(
column(6, "Trend - Usage of space",br(),
div(downloadLink("downloadspacetrend", "Download this chart"), style = "font-size:70%", align = "left")),
column(6,
div(checkboxInput(inputId = "spacetrendcheck", "Add to reports", value = FALSE),style = "font-size:70%",float = "right", align = "right", direction = "rtl"))
),
div(plotOutput("spacetrend"), width = "100%", height = "400px", style = "font-size:90%;"),
uiOutput("spacetrendcomment")
)
)
)
)
)
)
server <- function(input, output, session) {
}
shinyApp(ui = ui, server = server)
I want the "Add to reports" check box to the right end of the box. I tried using float, direction arguments with and without, but not getting the desired output.
There is the following reason for you problem: The header title's width is not set to the whole width of the box. Instead, its width is calculated from the elements it contains. This makes the columns (which are 50% title width) also depend on the elements. Your elements however are not that big, so the resulting div is in itself well divided in two equally large columns, but they together don't span the whole box width.
You can just fix the title width to 100% (box header width), which as a result tells the columns to be that large, whatever their content might be.
This is a one line addition.
Note that the style addition in the code below affects all box titles. But I believe that this is never really a problem.
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
skin = "green",
dashboardHeader(
title = "TEST", titleWidth = 225
),
dashboardSidebar(
menuItem("TRENDS", tabName = "vactr", icon = shiny::icon("line-chart"))
),
dashboardBody(
tabItems(
tabItem(tabName = "vactr",
fluidRow(
box(width = 12, status = "info", title =
fluidRow(
tags$style(".box-title {width: 100%;}"),
column(6, "Trend - Usage of space",br(),
div(downloadLink("downloadspacetrend", "Download this chart"), style = "font-size:70%", align = "left")),
column(6,
div(checkboxInput(inputId = "spacetrendcheck", "Add to reports", value = FALSE),style = "font-size:70%",float = "right", align = "right", direction = "rtl"))
),
div(plotOutput("spacetrend"), width = "100%", height = "400px", style = "font-size:90%;"),
uiOutput("spacetrendcomment")
)
)
)
)
)
)
server <- function(input, output, session) {}
shinyApp(ui = ui, server = server)
Im using jfreecharts for my application. I need to remove the x-axis line in the Line chart produced. How can i remove the axis line, Any help would be appreciated.
To remove your axis line and tick marks, refer this code.
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(1.0, "Line", "2009");
dataset.addValue(2.0, "Line", "2010");
dataset.addValue(null, "Line", "2011");
dataset.addValue(3.0, "Line", "2012");
final JFreeChart chart = ChartFactory.createLineChart(
"", // chart title
"", // domain axis label
"", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
false, // include legend
false, // tooltips
false // urls
);
chart.setBackgroundPaint(Color.WHITE);
final CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint(Color.WHITE);
plot.setRangeZeroBaselinePaint(Color.RED);
plot.setOutlineVisible(false);
plot.setRangeGridlinePaint(Color.white);
plot.setDomainGridlinePaint(Color.BLUE);
final CategoryAxis categoryAxis = (CategoryAxis) plot.getDomainAxis();
categoryAxis.setAxisLineVisible(false);
categoryAxis.setTickMarksVisible(false);
//categoryAxis.setVisible(false);
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
//rangeAxis.setAxisLineVisible(false);
rangeAxis.setVisible(false);
rangeAxis.setLabelPaint(Color.BLUE);
rangeAxis.setRange(0, 3);
final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
//renderer.setItemLabelsVisible(false); //Deprecated.
renderer.setBaseShapesVisible(true);
renderer.setBaseShapesFilled(true);
renderer.setSeriesStroke(0, new BasicStroke(2.0f));
Shape circle = new Ellipse2D.Double(-3, -3, 6, 6);
renderer.setSeriesShape(0, circle);
plot.getRenderer().setSeriesPaint(0, Color.BLUE);
try {
ChartUtilities.saveChartAsPNG(new File("E:\\jfreeLinechart.png"), chart, 211, 90);
System.out.println("=====chart=====");
} catch (Exception e) {
e.printStackTrace();
}
Also refer this link
I am using Nevron Charting Control ver.11.1.17.12 in application. I am facing problem in drawing the chart correct with the DateTimeScaleConfigurator. Here are following problem:
Series Bar overlapping each other if series count increases.
Series getting out of the Axis lines.
X Axis Scale automatically add previous year December and next year Jan in the scale which cause the chart to have blank area in case of Surface Chart.
//code snippet to draw Bar Chart Series
NBarSeries bar = new NBarSeries();
bar.UniqueId = new Guid(outputVariable.UniqueId);
bar.Name = outputVariable.LegendText;
chart.Series.Add(bar);
bar.HasBottomEdge = false;
bar.MultiBarMode = chart.Series.Count == 1 ? MultiBarMode.Series : MultiBarMode.Clustered;
// bar.InflateMargins = true;
bar.UseZValues = false;
indexOfSeries = chart.Series.IndexOf(bar);
ConfigureChartSeries(bar, indexOfSeries, outputVariable);
SetSeriesAxisInformation(bar, outputVariable.Unit);
bar.UseXValues = true;
foreach (DataRow row in seriesDataTable.Rows)
{
bar.XValues.Add(Convert.ToDateTime(row["TimeStamp"]).ToOADate());
}
code snippet to Add Surface Chart Series
chart.Enable3D = true;
chart.BoundsMode = BoundsMode.Stretch;
(chart as NCartesianChart).Fit3DAxisContent = true;
chart.Projection.SetPredefinedProjection(PredefinedProjection.OrthogonalTop);
chart.LightModel.EnableLighting = false;
chart.Wall(ChartWallType.Back).Visible = false;
chart.Wall(ChartWallType.Left).Visible = false;
chart.Wall(ChartWallType.Floor).Visible = false;
// setup Y axis
chart.Axis(StandardAxis.PrimaryY).Visible = false;
// setup Z axis
NAxis axisZ = chart.Axis(StandardAxis.Depth);
axisZ.Anchor = new NDockAxisAnchor(AxisDockZone.TopLeft);
NLinearScaleConfigurator scaleZ = new NLinearScaleConfigurator();
scaleZ.InnerMajorTickStyle.Visible = false;
scaleZ.MajorGridStyle.ShowAtWalls = new ChartWallType[0];
scaleZ.RoundToTickMin = false;
scaleZ.RoundToTickMax = false;
axisZ.ScaleConfigurator = scaleZ;
axisZ.Visible = true;
// add a surface series
NGridSurfaceSeries surface = new NGridSurfaceSeries();
surface.UniqueId = new Guid(outputVariable.UniqueId);
surface.Name = outputVariable.LegendText;
chart.Series.Add(surface);
surface.Legend.Mode = SeriesLegendMode.SeriesLogic;
surface.ValueFormatter = new NNumericValueFormatter("0.0");
surface.FillMode = SurfaceFillMode.Zone;
surface.FrameMode = SurfaceFrameMode.Contour;
surface.ShadingMode = ShadingMode.Flat;
surface.DrawFlat = true;
// Already set this property to false and working in other chart.
surface.InflateMargins = false;
surface.FrameColorMode = SurfaceFrameColorMode.Zone;
surface.SmoothPalette = true;
surface.Legend.Format = "<zone_value>";
surface.FillMode = SurfaceFillMode.Zone;
surface.FrameMode = SurfaceFrameMode.Contour;
CreateSurfaceSeries(outputVariable, surface);
chartControl.Refresh();
And the ScaleConfigurator configuration
chartPrimaryXAxis = chart.Axis(StandardAxis.PrimaryX);
// X Axis Configuration
dateTimeScale = new NDateTimeScaleConfigurator();
dateTimeScale.Title.Text = string.Empty;
dateTimeScale.LabelStyle.Angle = new NScaleLabelAngle(ScaleLabelAngleMode.Scale, 90);
dateTimeScale.LabelStyle.ContentAlignment = ContentAlignment.MiddleLeft;
dateTimeScale.LabelStyle.TextStyle.FontStyle = new NFontStyle("Times New Roman", 6);
dateTimeScale.LabelFitModes = new LabelFitMode[] { LabelFitMode.AutoScale };
chartPrimaryXAxis.ScaleConfigurator = dateTimeScale;
chartPrimaryXAxis.ScrollBar.ResetButton.Visible = true;
chartPrimaryXAxis.ScrollBar.ShowSliders = true;
dateTimeScale.EnableUnitSensitiveFormatting = true;
Here is the generated output:
Any idea regarding this problem will be deeply appreciated.
Thanks in advance.
Series Bar overlapping each other if series count increases.
&
Series bar getting out of the Axis lines.
Answer: When you are using categorial data then use NOrdinalScaleConfigurator rather than NDateTimeScaleConfigurator. It will not solve the problem and put the series bar in the center of the scale and auto resize them according to the chart size also.
X Axis Scale automatically add previous year December and next year
Jan in the scale which cause the chart to have blank area in case of
Surface Chart.
Answer:
Set the following properties of the DateTimeScaleConfigurator to false to avoid such behavior.
dateTimeScale.RoundToTickMax = false;
dateTimeScale.RoundToTickMin = false;