How to combine a bar chart and a line chart in JFreeChart - bar-chart

I want to combine a line chart and a bar chart in a JFreeChart chart. What I've got so far is two lines. I have to change the renderer of one of the lines to a BarRenderer somehow. This is what I've got so far:
barDataset = new TimeSeriesCollection();
lineDataset = new TimeSeriesCollection();
totalDistanceSeries = new TimeSeries("Total Distance");
movingAverageSeries = new TimeSeries("Moving Average");
while (rs.next()) {
myDate = rs.getDate("Date");
d = new Day(myDate);
totalDistance = rs.getDouble("TotaleAfstand");
movingAverage = rs.getDouble("MovingAverage");
totalDistanceSeries.add(d,totalDistance);
movingAverageSeries.add(d,movingAverage);
}
barDataset.addSeries(totalDistanceSeries);
lineDataset.addSeries(movingAverageSeries);
String chartTitle = "Monthly Chart with Moving Average";
String xAxisLabel = "Date";
String yAxisLabel = "TotalDistance";
JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle,
xAxisLabel, yAxisLabel, lineDataset);
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer();
renderer.setBaseShapesVisible(true);
XYPlot plot = (XYPlot) chart.getXYPlot();
plot.setDataset(1, barDataset);
chartPanel = new ChartPanel(chart);
chartPanel.setLocation(10,60);
chartPanel.setSize(1850, 900);
add(chartPanel);
Does someone know how to do this?

I needed a XYBarRenderer instead of just a BarRenderer. This is the code I added below
plot.setDataset(1, barDataset); :
XYBarRenderer renderer2=new XYBarRenderer(0.20);
plot.setRenderer(1, renderer2);

Related

Table is distorted while comparing HTML data using daisydiff.jar

Left side table is distorted while comparing two HTML table data using daisydiff.jar.
I need your support to fix this issue. Thanks in advance
Using below code
StringWriter finalResult = new StringWriter();
SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); TransformerHandler result = tf.newTransformerHandler();
result.getTransformer().setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
result.getTransformer().setOutputProperty(OutputKeys.INDENT, "no");
result.getTransformer().setOutputProperty(OutputKeys.METHOD, "html");
result.getTransformer().setOutputProperty(OutputKeys.ENCODING, "UTF-8");
result.setResult(new StreamResult(finalResult));
ContentHandler postProcess = result;
Locale locale = Locale.getDefault();
String prefix = "diff";
NekoHtmlParser cleaner = new NekoHtmlParser();
InputSource oldSource = new InputSource (new String reader(html1));
InputSource newSource = new InputSource (new String reader(html2));
DomTreeBuilder oldHandler = new DomTreeBuilder ();
cleaner.parse(oldSource, oldHandler);
TextNodeComparator leftComparator = new TextNodeComparator (oldHandler, locale);
DomTreeBuilder newHandler = new DomTreeBuilder ();
cleaner.parse(newSource, newHandler);
TextNodeComparator rightComparator = new TextNodeComparator (newHandler, locale);
HtmlSaxDiffOutput output = new HtmlSaxDiffOutput (postProcess, prefix);
HTMLDiffer differ = new HTMLDiffer(output);
differ.diff(leftComparator, rightComparator);

How to Change the Y axis of an Primefaces 7.0 ChartJS Linechart with Java?

With the new version of Primefaces (7.0) the jqplot-charts got replaced by ChartJS Charts. Now I want the Y-Axis of my chart to be longer. With the old charts this was easily possible in Java but now I don't know how to do it. If it isn't possible in Java is there an alternative way to change the Y-Axis of an existing chart?
It all right in the showcase in the 2nd example for Cartesian Line Model.
https://www.primefaces.org/showcase/ui/chartjs/line.xhtml
public void createCartesianLinerModel() {
cartesianLinerModel = new LineChartModel();
ChartData data = new ChartData();
LineChartDataSet dataSet = new LineChartDataSet();
List<Number> values = new ArrayList<>();
values.add(20);
values.add(50);
values.add(100);
values.add(75);
values.add(25);
values.add(0);
dataSet.setData(values);
dataSet.setLabel("Left Dataset");
dataSet.setYaxisID("left-y-axis");
LineChartDataSet dataSet2 = new LineChartDataSet();
List<Number> values2 = new ArrayList<>();
values2.add(0.1);
values2.add(0.5);
values2.add(1.0);
values2.add(2.0);
values2.add(1.5);
values2.add(0);
dataSet2.setData(values2);
dataSet2.setLabel("Right Dataset");
dataSet2.setYaxisID("right-y-axis");
data.addChartDataSet(dataSet);
data.addChartDataSet(dataSet2);
List<String> labels = new ArrayList<>();
labels.add("Jan");
labels.add("Feb");
labels.add("Mar");
labels.add("Apr");
labels.add("May");
labels.add("Jun");
data.setLabels(labels);
cartesianLinerModel.setData(data);
//Options
LineChartOptions options = new LineChartOptions();
CartesianScales cScales = new CartesianScales();
CartesianLinearAxes linearAxes = new CartesianLinearAxes();
linearAxes.setId("left-y-axis");
linearAxes.setPosition("left");
CartesianLinearAxes linearAxes2 = new CartesianLinearAxes();
linearAxes2.setId("right-y-axis");
linearAxes2.setPosition("right");
cScales.addYAxesData(linearAxes);
cScales.addYAxesData(linearAxes2);
options.setScales(cScales);
Title title = new Title();
title.setDisplay(true);
title.setText("Cartesian Linear Chart");
options.setTitle(title);
cartesianLinerModel.setOptions(options);
}

GridView - Editable ComboBox Data become slow

this is the code which i custom the column in gridview to show the data. i try to get the data from editable text that i type from comboBox, but the data output become too slow to appear in list
settings.Columns.Add(column =>
{
column.FieldName = "Food";
column.Caption = "Food List";
column.Width = 350;
column.ColumnType = MVCxGridViewColumnType.ComboBox;
var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
comboBoxProperties.Width = new System.Web.UI.WebControls.Unit(350);
comboBoxProperties.DataSource = Food.Shared.ListFood;
comboBoxProperties.TextField = "Value";
comboBoxProperties.ValueField = "Key";
comboBoxProperties.ValueType = typeof(Guid);
comboBoxProperties.IncrementalFilteringMode = IncrementalFilteringMode.Contains;
comboBoxProperties.ItemStyle.Wrap = DefaultBoolean.True;
comboBoxProperties.ClientInstanceName = "foodListTo";
});

Can't load a service for category "ExternalGraphicFactory"

I'm using geotools-18.5, with JavaFx in Inteliji IDE.
When I want to create PointSymbolizer from a svg or png image.
StyleBuilder builder = new StyleBuilder();
ExternalGraphic extGraphic = builder.createExternalGraphic("file:/home/cuongnv/test.svg", "svg");
I build code OK, but when run, I received warning:
WARNING: Can't load a service for category "ExternalGraphicFactory".
Provider org.geotools.renderer.style.ImageGraphicFactory could not be
instantiated.
Can someone help me ?
Here is full code:
private Style createStyleBuilder(){
StyleBuilder builder = new StyleBuilder();
FilterFactory2 ff = builder.getFilterFactory();
// RULE 1
// first rule to draw cities
// define a point symbolizer representing a city
Graphic city = builder.createGraphic();
city.setSize(ff.literal(50));
ExternalGraphic extGraphic = builder.createExternalGraphic("file:/home/cuongnv/Javafx/GeoTool/geotools_fx_tutorial-master/geotools-fx/src/main/resources/images/console.svg", "svg"); // svg
city.addExternalGraphic(extGraphic);
PointSymbolizer pointSymbolizer = builder.createPointSymbolizer(city);
Rule rule1 = builder.createRule(pointSymbolizer);
rule1.setName("rule1");
rule1.getDescription().setTitle("City");
rule1.getDescription().setAbstract("Rule for drawing cities");
Rule rules[] = new Rule[] {rule1};
FeatureTypeStyle featureTypeStyle = builder.createFeatureTypeStyle("Feature", rules);
Style style = builder.createStyle();
style.setName("style");
style.getDescription().setTitle("User Style");
style.getDescription().setAbstract("Definition of Style");
style.featureTypeStyles().add(featureTypeStyle);
return style;
}
TYPE = DataUtilities.createType(
"Dataset",
"geometry:Geometry:srid=4326"
+ ","
+ "name:String,"
+ "id:String"
);
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
com.vividsolutions.jts.geom.Point point = geometryFactory.createPoint(new Coordinate(x,y));
featureBuilder.add(point);
SimpleFeature feature = featureBuilder.buildFeature(null);
DefaultFeatureCollection featureCollection = new DefaultFeatureCollection("internal", TYPE);
featureCollection.add(feature);
Style style = createStyleBuilder();
Layer layer = new FeatureLayer(featureCollection, style);
layer.setTitle("New Point");
mapContent.layers().add(layer);
You have set the image mime type incorrectly, it should be:
ExternalGraphic extGraphic = builder.createExternalGraphic("file:/stuff/ian/geoserver/data/styles/burg02.svg", "image/svg"); // svg
and all will work.
EDIT
If you are still having issues then try adding this code to the end of the createStyle module and look at the generated SVG, possibly in GeoServer to test it out.
SLDTransformer styleTransform = new SLDTransformer();
StyledLayerDescriptor sld = sf.createStyledLayerDescriptor();
UserLayer layer = sf.createUserLayer();
layer.setLayerFeatureConstraints(new FeatureTypeConstraint[] {null});
sld.addStyledLayer(layer);
layer.addUserStyle(style);
try {
String xml = styleTransform.transform(sld);
System.out.println(xml);
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Charting in windows phone app

I want to create a chart using amchart in windows phone application.This is my code when i run i have this message"Can not implicitly convert type 'string' to 'System.Windows.Media.Brush"how can i solve this
InitializeComponent();
XDocument data = XDocument.Load("Data.xml");
var results = from query in data.Descendants("year")
select new ResultModel((string)query.Element("month"),
(int)query.Element("actual"));
var chart = new SerialChart
{
CategoryValueMemberPath = "month",
AxisForeground="White",
PlotAreaBackground="Black",
GridStroke="DarkGray"
};
chart.SetBinding(SerialChart.DataSourceProperty, new Binding("results"));
var lineGraph = new LineGraph
{
Title = "Sales",
ValueMemberPath = "actual",
};
chart.Graphs.Add(lineGraph);
sta.Children.Add(chart);
}
The properties in SerialChart, such as AxisForeground, PlotAreaBackground, GridStroke, their type is Brush. So you can set it like:
AxisForeground = new SolidColorBrush(Colors.White);
PlotAreaBackground = new SolidColorBrush(Colors.Black);
GridStroke = new SolidColorBrush(Colors.DarkGray);